Skip to content

Commit

Permalink
Fix inprogress test detection
Browse files Browse the repository at this point in the history
In #4 we attempted to add an error message when a test fails prior to
reporting its final status (like in case of a segfault). However, that
PR didn't work as intended because the condition to check if there were
any tests inprogress was incorrect. It relied on the count_tests()
function in subunit_trace which was returning zero as it was called
there even when tests were left in the inprogress state. However, this
call wasn't actually needed because we call get_stuck_in_progress()
right before the condition which collects any test ids from the subunit
stream that are left inprogress. This commit fixes the issue by just
checking that the output list from get_stuck_in_progress() has entries.
Then to ensure this doesn't regress in the future the unittest added in
PR #304 is updated to actually assert we write out the error message as
expected. Previously it only checked the return code was a failure
(which it was even before #304) which is what let this issue slip in.
  • Loading branch information
mtreinish committed Aug 30, 2021
1 parent 7d655e4 commit a09d24f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stestr/subunit_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions stestr/tests/test_subunit_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit a09d24f

Please sign in to comment.