mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-31 13:03:02 +02:00
test: Log the output of failing subprocesses
It is not uncommon for subprocesses to fail when developing new tests, but the default representation of CalledProcessError does not print the stdout of the program, only that it failed. Catch this common case when a test is about to fail, and make sure to log any output it produced.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import contextlib
|
||||
import datetime
|
||||
import subprocess
|
||||
import sys
|
||||
import traceback
|
||||
|
||||
@@ -30,6 +31,11 @@ class Test:
|
||||
|
||||
traceback.print_exception(e, file=self.commenter)
|
||||
|
||||
if type(e) is subprocess.CalledProcessError:
|
||||
print("Failing subprocess stdout:\n", e.stdout)
|
||||
elif len(e.args) and type(e.args[0]) is subprocess.CompletedProcess:
|
||||
print("Failing subprocess stdout:\n", e.args[0].stdout)
|
||||
|
||||
raise SystemExit(1)
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
||||
Reference in New Issue
Block a user