Comments
Patch
@@ -1389,18 +1389,21 @@ class TestSuite(unittest.TestSuite):
except: # re-raises
done.put(('!', test, 'run-test raised an error, see traceback'))
raise
+ stoppedearly = False
+
try:
while tests or running:
if not done.empty() or running == self._jobs or not tests:
try:
done.get(True, 1)
+ running -= 1
if result and result.shouldStop:
+ stoppedearly = True
break
except queue.Empty:
continue
- running -= 1
if tests and not running == self._jobs:
test = tests.pop(0)
if self._loop:
if getattr(test, 'should_reload', False):
@@ -1412,8 +1415,20 @@ class TestSuite(unittest.TestSuite):
t = threading.Thread(target=job, name=test.name,
args=(test, result))
t.start()
running += 1
+
+ # If we stop early we still need to wait on started tests to
+ # finish. Otherwise, there is a race between the test completing
+ # and the test's cleanup code running. This could result in the
+ # test reporting incorrect.
+ if stoppedearly:
+ while running:
+ try:
+ done.get(True, 1)
+ running -= 1
+ except queue.Empty:
+ continue
except KeyboardInterrupt:
for test in runtests:
test.abort()
@@ -229,9 +229,10 @@ failures in parallel with --first should
This is a noop statement so that
this test is still more bytes than success.
Failed test-failure*.t: output changed (glob)
- # Ran 2 tests, 0 skipped, 0 warned, 1 failed.
+ Failed test-nothing.t: output changed
+ # Ran 2 tests, 0 skipped, 0 warned, 2 failed.
python hash seed: * (glob)
[1]