summaryrefslogtreecommitdiffstats
path: root/Lib/unittest/test/test_case.py
diff options
context:
space:
mode:
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 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