diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2014-04-28 23:25:07 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2014-04-28 23:25:07 (GMT) |
commit | b1e58440f87f921bd51396f4e9a4b18dcd2def6b (patch) | |
tree | 1a2bc9fbf06db1f5df349b53251ddc79dedafb47 /Lib/unittest/test | |
parent | a171979a19b46194f2926522073622d64d7a8fc6 (diff) | |
parent | 9681022f1ee5c6c9160c515b24d2a3d1efe8b90d (diff) | |
download | cpython-b1e58440f87f921bd51396f4e9a4b18dcd2def6b.zip cpython-b1e58440f87f921bd51396f4e9a4b18dcd2def6b.tar.gz cpython-b1e58440f87f921bd51396f4e9a4b18dcd2def6b.tar.bz2 |
Issue #9815: assertRaises now tries to clear references to local variables in the exception's traceback.
Diffstat (limited to 'Lib/unittest/test')
-rw-r--r-- | Lib/unittest/test/test_assertions.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/unittest/test/test_assertions.py b/Lib/unittest/test/test_assertions.py index af08d5a..c349a95 100644 --- a/Lib/unittest/test/test_assertions.py +++ b/Lib/unittest/test/test_assertions.py @@ -1,5 +1,6 @@ import datetime import warnings +import weakref import unittest from itertools import product @@ -97,6 +98,36 @@ class Test_Assertions(unittest.TestCase): else: self.fail("assertRaises() didn't let exception pass through") + def test_assertRaises_frames_survival(self): + # Issue #9815: assertRaises should avoid keeping local variables + # in a traceback alive. + class A: + pass + wr = None + + class Foo(unittest.TestCase): + + def foo(self): + nonlocal wr + a = A() + wr = weakref.ref(a) + try: + raise IOError + except IOError: + raise ValueError + + def test_functional(self): + self.assertRaises(ValueError, self.foo) + + def test_with(self): + with self.assertRaises(ValueError): + self.foo() + + Foo("test_functional").run() + self.assertIsNone(wr()) + Foo("test_with").run() + self.assertIsNone(wr()) + def testAssertNotRegex(self): self.assertNotRegex('Ala ma kota', r'r+') try: |