bpo-33746: Fix test_unittest.testRegisterResult() in verbose mode (GH-7799)

Only make sure that the result is in unittest.signals._results, don't
check the full content of unittest.signals._results.

support._run_suite() uses TextTestRunner in verbose mode, but
TextTestRunner.run() calls registerResult(result) which made the test
fail with "odd object in result set".

Call also removeResult() to restore unittest.signals._results to
avoid test side effect.
This commit is contained in:
Victor Stinner 2018-06-20 11:29:33 +02:00 committed by GitHub
parent 9bb92235f6
commit fd8fbce495
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 9 deletions

View File

@ -39,16 +39,13 @@ class TestBreak(unittest.TestCase):
def testRegisterResult(self):
result = unittest.TestResult()
self.assertNotIn(result, unittest.signals._results)
unittest.registerResult(result)
for ref in unittest.signals._results:
if ref is result:
break
elif ref is not result:
self.fail("odd object in result set")
else:
self.fail("result not found")
try:
self.assertIn(result, unittest.signals._results)
finally:
unittest.removeResult(result)
def testInterruptCaught(self):
default_handler = signal.getsignal(signal.SIGINT)

View File

@ -0,0 +1 @@
Fix test_unittest when run in verbose mode.