summaryrefslogtreecommitdiff
path: root/Lib/unittest/test/test_case.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-06-16 00:18:15 +0200
committerGitHub <noreply@github.com>2017-06-16 00:18:15 +0200
commit50dbf577e10f806056d60ac956db0748d2cc8257 (patch)
treef28a773dacfbfee77ef7d04da81f0c4be19e2707 /Lib/unittest/test/test_case.py
parente064d4dfeda09fd206653697b70b434e98cc1b57 (diff)
downloadcpython-git-50dbf577e10f806056d60ac956db0748d2cc8257.tar.gz
bpo-23890: Fix ref cycle in TestCase.assertRaises (#858)
unittest.TestCase.assertRaises() now manually breaks a reference cycle to not keep objects alive longer than expected. (cherry picked from commit bbd3cf8f1ef1e91a8d6dac6411e18b4b9084abf5)
Diffstat (limited to 'Lib/unittest/test/test_case.py')
-rw-r--r--Lib/unittest/test/test_case.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_case.py b/Lib/unittest/test/test_case.py
index 8f752b8ae0..b849591505 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