From 6a7edee64c13d06e02b5eef554d9d6d10dcb71c0 Mon Sep 17 00:00:00 2001 From: Eli Bendersky Date: Tue, 25 Jan 2022 12:45:05 -0800 Subject: Improve error reporting from test_examples Emit stderr as well as stdout from the example in case of failure --- tests/test_examples.py | 4 ++-- tests/test_util.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_examples.py b/tests/test_examples.py index 3c516e1..7fb2ad3 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -21,12 +21,12 @@ class TestExamplesSucceed(unittest.TestCase): # Use it when we finally drop Python 2... path = os.path.join(root, filename) t1 = time.time() - rc, stdout = run_exe(path) + rc, stdout, stderr = run_exe(path) elapsed = time.time() - t1 if EMIT_ELAPSED_TIME: print('{}... elapsed: {}'.format(filename, elapsed)) self.assertEqual( - rc, 0, 'example "{}" failed with stdout =\n{}'.format(filename, stdout)) + rc, 0, 'example "{}" failed with stdout =\n{}\nstderr =\n{}'.format(filename, stdout, stderr)) if __name__ == '__main__': diff --git a/tests/test_util.py b/tests/test_util.py index 38dfdf5..a945c29 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -42,7 +42,7 @@ def _bytes2str(b): def run_exe(exe_path, args=[], echo=False): """ Runs the given executable as a subprocess, given the list of arguments. Captures its return code (rc) and stdout and - returns a pair: rc, stdout_str + returns a tuple: rc, stdout, stderr """ popen_cmd = [exe_path] + args if os.path.splitext(exe_path)[1] == '.py': @@ -50,5 +50,5 @@ def run_exe(exe_path, args=[], echo=False): if echo: print('[cmd]', ' '.join(popen_cmd)) proc = subprocess.Popen(popen_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - proc_stdout = proc.communicate()[0] - return proc.returncode, _bytes2str(proc_stdout) + stdout, stderr = proc.communicate() + return proc.returncode, _bytes2str(stdout), _bytes2str(stderr) -- cgit v1.2.1