(self)
| 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 | |
| 2344 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected