Skip to content

Commit

Permalink
test: helper: Print stdout on timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Vyacheslav Yurkov <[email protected]>
  • Loading branch information
UVV-gh committed Sep 7, 2023
1 parent 191bd51 commit 5d0ea94
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions test/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,24 @@ def run(command, *, timeout=30):
logger = logger_from_command(command)
logger.info('running: %s', command)

proc = subprocess.run(shlex.split(command), capture_output=True, text=True, check=False,
timeout=timeout)

for line in proc.stdout.splitlines():
if line:
logger.info('stdout: %s', line)
for line in proc.stderr.splitlines():
if line:
logger.warning('stderr: %s', line)
def stdout_print_helper(logger, prefix, stdout):
if stdout is None:
return

for line in stdout.splitlines():
if line:
logger.info(f'{prefix}: %s', line)

try:
proc = subprocess.run(shlex.split(command), capture_output=True, text=True, check=False,
timeout=timeout)
except subprocess.TimeoutExpired as e:
stdout_print_helper(logger, "stdout", e.stdout)
stdout_print_helper(logger, "stderr", e.stderr)
raise

stdout_print_helper(logger, "stdout", proc.stdout)
stdout_print_helper(logger, "stderr", proc.stderr)

logger.info('exitcode: %d', proc.returncode)

Expand Down

0 comments on commit 5d0ea94

Please sign in to comment.