MCPcopy Index your code
hub / github.com/python/cpython / test_no_exception_leak

Method test_no_exception_leak

Lib/test/test_unittest/test_case.py:2316–2341  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2314 self.assertFalse(wr())
2315
2316 def test_no_exception_leak(self):
2317 # Issue #19880: TestCase.run() should not keep a reference
2318 # to the exception
2319 class MyException(Exception):
2320 ninstance = 0
2321
2322 def __init__(self):
2323 MyException.ninstance += 1
2324 Exception.__init__(self)
2325
2326 def __del__(self):
2327 MyException.ninstance -= 1
2328
2329 class TestCase(unittest.TestCase):
2330 def test1(self):
2331 raise MyException()
2332
2333 @unittest.expectedFailure
2334 def test2(self):
2335 raise MyException()
2336
2337 for method_name in ('test1', 'test2'):
2338 testcase = TestCase(method_name)
2339 testcase.run()
2340 gc_collect() # For PyPy or other GCs.
2341 self.assertEqual(MyException.ninstance, 0)
2342
2343
2344if __name__ == "__main__":

Callers

nothing calls this directly

Calls 4

runMethod · 0.95
gc_collectFunction · 0.90
TestCaseClass · 0.70
assertEqualMethod · 0.45

Tested by

no test coverage detected