Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/python: improve reporting when a command fails #6718

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions tests/python/shared/fixtures/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
import os
import shlex
from enum import Enum
from http import HTTPStatus
from pathlib import Path
Expand Down Expand Up @@ -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():
Expand Down
Loading