From a3c82f19b8882462a446ea88ccc3d5368d6086e1 Mon Sep 17 00:00:00 2001 From: Joonas Koivunen Date: Thu, 5 Oct 2023 23:15:55 +0300 Subject: [PATCH] tests: prettier subprocess output in test log (#5485) 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. --- test_runner/fixtures/neon_fixtures.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/test_runner/fixtures/neon_fixtures.py b/test_runner/fixtures/neon_fixtures.py index c8b970100bac..feac846a4c82 100644 --- a/test_runner/fixtures/neon_fixtures.py +++ b/test_runner/fixtures/neon_fixtures.py @@ -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