From 9fb60b7f4bf655d22a032959390ee5eebf2b2c81 Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Tue, 22 Aug 2023 18:11:20 +0300 Subject: [PATCH] tests/python: improve reporting when a command fails (#6718) * represent the command accurately using shell quoting; * show the exit code; * show both stdout and stderr. --- tests/python/shared/fixtures/init.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/python/shared/fixtures/init.py b/tests/python/shared/fixtures/init.py index 801fa609e4f..56280dfeb5e 100644 --- a/tests/python/shared/fixtures/init.py +++ b/tests/python/shared/fixtures/init.py @@ -4,6 +4,7 @@ import logging import os +import shlex from enum import Enum from http import HTTPStatus from pathlib import Path @@ -103,12 +104,13 @@ def _run(command, capture_output=True): proc = run(_command) # nosec return stdout, stderr except CalledProcessError as exc: - stderr = exc.stderr.decode() or exc.stdout.decode() if capture_output else "see above" - pytest.exit( - f"Command failed: {command}.\n" - f"Error message: {stderr}.\n" - "Add `-s` option to see more details" - ) + message = f"Command failed: {' '.join(map(shlex.quote, _command))}." + message += f"\nExit code: {exc.returncode}" + if capture_output: + message += f"\nStandard output:\n{exc.stdout.decode()}" + message += f"\nStandard error:\n{exc.stderr.decode()}" + + pytest.exit(message) def _kube_get_server_pod_name():