From b6cf866f52f521bf367703f8ca35df7a924f9949 Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Tue, 14 May 2024 14:16:46 +0000 Subject: [PATCH] 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. --- test/infamy/tap.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/infamy/tap.py b/test/infamy/tap.py index 28a6506c..22ceb05a 100644 --- a/test/infamy/tap.py +++ b/test/infamy/tap.py @@ -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