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:
Tobias Waldekranz
2024-05-20 16:21:06 +02:00
parent 2c72aaf6e1
commit b6cf866f52
+6
View File
@@ -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