mirror of
https://github.com/python/cpython.git
synced 2025-08-01 23:53:15 +00:00
Close #19880: Fix a reference leak in unittest.TestCase. Explicitly break
reference cycles between frames and the _Outcome instance.
This commit is contained in:
parent
28dd6deca8
commit
031bd532c4
3 changed files with 42 additions and 1 deletions
|
@ -1533,6 +1533,32 @@ test case
|
|||
del case
|
||||
self.assertFalse(wr())
|
||||
|
||||
def test_no_exception_leak(self):
|
||||
# Issue #19880: TestCase.run() should not keep a reference
|
||||
# to the exception
|
||||
class MyException(Exception):
|
||||
ninstance = 0
|
||||
|
||||
def __init__(self):
|
||||
MyException.ninstance += 1
|
||||
Exception.__init__(self)
|
||||
|
||||
def __del__(self):
|
||||
MyException.ninstance -= 1
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
def test1(self):
|
||||
raise MyException()
|
||||
|
||||
@unittest.expectedFailure
|
||||
def test2(self):
|
||||
raise MyException()
|
||||
|
||||
for method_name in ('test1', 'test2'):
|
||||
testcase = TestCase(method_name)
|
||||
testcase.run()
|
||||
self.assertEqual(MyException.ninstance, 0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue