diff --git a/stestr/subunit_trace.py b/stestr/subunit_trace.py index 0d3c1dd..a89ea11 100644 --- a/stestr/subunit_trace.py +++ b/stestr/subunit_trace.py @@ -426,8 +426,8 @@ def trace(stdin, stdout, print_failures=False, failonly=False, print("\nNo tests were successful during the run", file=sys.stderr) return 1 in_progress = get_stuck_in_progress() - if count_tests('status', '^inprogress$') > 0: - print("\nThe following tests exited without returning a status \n" + if in_progress: + print("\nThe following tests exited without returning a status\n" "and likely segfaulted or crashed Python:", file=sys.stderr) for test in in_progress: print("\n\t* %s" % test, file=sys.stderr) diff --git a/stestr/tests/test_subunit_trace.py b/stestr/tests/test_subunit_trace.py index c7fbe86..5e8d461 100644 --- a/stestr/tests/test_subunit_trace.py +++ b/stestr/tests/test_subunit_trace.py @@ -122,6 +122,23 @@ def test_trace_with_stuck_inprogress(self): timestamp=dt.now(UTC)) stream.stopTestRun() output.seek(0) + # capture stderr for test + stderr = io.StringIO() + sys_err = sys.stderr + sys.stderr = stderr + + def restore_stderr(): + sys.stderr = sys_err + + self.addCleanup(restore_stderr) stdin = io.TextIOWrapper(io.BufferedReader(output)) returncode = subunit_trace.trace(stdin, sys.stdout) self.assertEqual(1, returncode) + stderr.seek(0) + expected = """ +The following tests exited without returning a status +and likely segfaulted or crashed Python: + +\t* test_segfault +""" + self.assertEqual(stderr.read(), expected)