mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
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.
This commit is contained in:
parent
6003db7db5
commit
bbd3cf8f1e
3 changed files with 46 additions and 22 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue