diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-03-27 22:56:28 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-27 22:56:28 (GMT) |
commit | bbd3cf8f1ef1e91a8d6dac6411e18b4b9084abf5 (patch) | |
tree | 38bdb93a32d6ad08bba502f3aedda22b60b6c845 /Lib/unittest/test | |
parent | 6003db7db5fec545c01923c198a5fdfca5a91538 (diff) | |
download | cpython-bbd3cf8f1ef1e91a8d6dac6411e18b4b9084abf5.zip cpython-bbd3cf8f1ef1e91a8d6dac6411e18b4b9084abf5.tar.gz cpython-bbd3cf8f1ef1e91a8d6dac6411e18b4b9084abf5.tar.bz2 |
Fix ref cycles in TestCase.assertRaises() (#193)
bpo-23890: unittest.TestCase.assertRaises() now manually breaks a
reference cycle to not keep objects alive longer than expected.
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r-- | Lib/unittest/test/test_case.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py index 8f752b8..b849591 100644 --- a/Lib/unittest/test/test_case.py +++ b/Lib/unittest/test/test_case.py @@ -1273,6 +1273,19 @@ test case with self.assertRaises(TypeError): self.assertRaises((ValueError, object)) + def testAssertRaisesRefcount(self): + # bpo-23890: assertRaises() must not keep objects alive longer + # than expected + def func() : + try: + raise ValueError + except ValueError: + raise ValueError + + refcount = sys.getrefcount(func) + self.assertRaises(ValueError, func) + self.assertEqual(refcount, sys.getrefcount(func)) + def testAssertRaisesRegex(self): class ExceptionMock(Exception): pass |