Skip to content

Commit

Permalink
Merge pull request #163 from UVV-gh/feature/improve-helper
Browse files Browse the repository at this point in the history
test: helper: Print stdout on timeout
  • Loading branch information
ejoerns authored Sep 29, 2023
2 parents 2757db4 + 5d0ea94 commit c57a1ee
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 c57a1ee

Please sign in to comment.