summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test/test_case.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-12-09 00:52:50 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-12-09 00:52:50 (GMT)
commit031bd532c48cf20a9cbf438bdae75dde49e36c51 (patch)
tree80052a8b6913721ca49b3a020cd989ec87ad0b06 /Lib/unittest/test/test_case.py
parent28dd6deca8afd79cd8c33731f01c108dd11257ab (diff)
downloadcpython-031bd532c48cf20a9cbf438bdae75dde49e36c51.zip
cpython-031bd532c48cf20a9cbf438bdae75dde49e36c51.tar.gz
cpython-031bd532c48cf20a9cbf438bdae75dde49e36c51.tar.bz2
Close #19880: Fix a reference leak in unittest.TestCase. Explicitly break
reference cycles between frames and the _Outcome instance.
Diffstat (limited to 'Lib/unittest/test/test_case.py')
-rw-r--r--Lib/unittest/test/test_case.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py
index 4b93179..658d23d 100644
--- a/Lib/unittest/test/test_case.py
+++ b/Lib/unittest/test/test_case.py
@@ -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()