mirror of
https://github.com/python/cpython.git
synced 2025-11-02 06:31:29 +00:00
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:
parent
9bb92235f6
commit
fd8fbce495
2 changed files with 7 additions and 9 deletions
|
|
@ -39,16 +39,13 @@ def testInstallHandler(self):
|
||||||
|
|
||||||
def testRegisterResult(self):
|
def testRegisterResult(self):
|
||||||
result = unittest.TestResult()
|
result = unittest.TestResult()
|
||||||
|
self.assertNotIn(result, unittest.signals._results)
|
||||||
|
|
||||||
unittest.registerResult(result)
|
unittest.registerResult(result)
|
||||||
|
try:
|
||||||
for ref in unittest.signals._results:
|
self.assertIn(result, unittest.signals._results)
|
||||||
if ref is result:
|
finally:
|
||||||
break
|
unittest.removeResult(result)
|
||||||
elif ref is not result:
|
|
||||||
self.fail("odd object in result set")
|
|
||||||
else:
|
|
||||||
self.fail("result not found")
|
|
||||||
|
|
||||||
|
|
||||||
def testInterruptCaught(self):
|
def testInterruptCaught(self):
|
||||||
default_handler = signal.getsignal(signal.SIGINT)
|
default_handler = signal.getsignal(signal.SIGINT)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Fix test_unittest when run in verbose mode.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue