Skip to content

Commit

Permalink
tests: prettier subprocess output in test log (#5485)
Browse files Browse the repository at this point in the history
Clean subprocess output so that:
- one line of output is just one line without a linebreak
    - like shells handle `echo subshell says: $(echo foo)`
- multiple lines are indented like other pytest output
- error output is dedented and then indented to be like other pytest
output

Minor readability changes remove friction.
  • Loading branch information
koivunej authored Oct 5, 2023
1 parent 8b15252 commit a3c82f1
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions test_runner/fixtures/neon_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,15 +1085,32 @@ def raw_cli(
stderr=subprocess.PIPE,
timeout=timeout,
)

indent = " "
if not res.returncode:
log.info(f"Run {res.args} success: {res.stdout}")
stripped = res.stdout.strip()
lines = stripped.splitlines()
if len(lines) < 2:
log.debug(f"Run {res.args} success: {stripped}")
else:
log.debug("Run %s success:\n%s" % (res.args, textwrap.indent(stripped, indent)))
elif check_return_code:
# this way command output will be in recorded and shown in CI in failure message
msg = f"""\
Run {res.args} failed:
stdout: {res.stdout}
stderr: {res.stderr}
indent = indent * 2
msg = textwrap.dedent(
"""\
Run %s failed:
stdout:
%s
stderr:
%s
"""
)
msg = msg % (
res.args,
textwrap.indent(res.stdout.strip(), indent),
textwrap.indent(res.stderr.strip(), indent),
)
log.info(msg)
raise RuntimeError(msg) from subprocess.CalledProcessError(
res.returncode, res.args, res.stdout, res.stderr
Expand Down

1 comment on commit a3c82f1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2318 tests run: 2196 passed, 0 failed, 122 skipped (full report)


Code coverage (full report)

  • functions: 52.5% (8119 of 15469 functions)
  • lines: 81.2% (47489 of 58499 lines)

The comment gets automatically updated with the latest test results
a3c82f1 at 2023-10-05T20:57:25.912Z :recycle:

Please sign in to comment.