mirror of
https://github.com/python/cpython.git
synced 2025-10-07 23:51:16 +00:00
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 bbd3cf8f1e
)
This commit is contained in:
parent
e064d4dfed
commit
50dbf577e1
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