summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-01-22 07:34:29 (GMT)
committerGitHub <noreply@github.com>2022-01-22 07:34:29 (GMT)
commitd4a9e34401d519250d3b3744cd10394069f748c1 (patch)
treeda5e2d0d78c2ac5ed11699cfa62c0eb6e6691608 /Lib/test
parent46e6aad12958d3b73c5377ec034d056bb1a36d65 (diff)
downloadcpython-d4a9e34401d519250d3b3744cd10394069f748c1.zip
cpython-d4a9e34401d519250d3b3744cd10394069f748c1.tar.gz
cpython-d4a9e34401d519250d3b3744cd10394069f748c1.tar.bz2
bpo-46442: improve and rename testExceptionCleanupNames (GH-30758)
The test tested that explicitly deleting the local variable bound to the exception did not cause problems, but it did not test what it actually claimed to test, i.e. that the variable is deleted automatically. (cherry picked from commit 82c53229e18f5853c82cb8ab6b9af1925a0e9e58) Co-authored-by: Yellow Dusk <yellow.dusk1590@fastmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_exceptions.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index b3d1c35..802dc9a 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -648,15 +648,27 @@ class ExceptionTests(unittest.TestCase):
self.assertTrue(str(Exception('a')))
self.assertTrue(str(Exception('a', 'b')))
- def testExceptionCleanupNames(self):
+ def test_exception_cleanup_names(self):
# Make sure the local variable bound to the exception instance by
# an "except" statement is only visible inside the except block.
try:
raise Exception()
except Exception as e:
- self.assertTrue(e)
+ self.assertIsInstance(e, Exception)
+ self.assertNotIn('e', locals())
+ with self.assertRaises(UnboundLocalError):
+ e
+
+ def test_exception_cleanup_names2(self):
+ # Make sure the cleanup doesn't break if the variable is explicitly deleted.
+ try:
+ raise Exception()
+ except Exception as e:
+ self.assertIsInstance(e, Exception)
del e
self.assertNotIn('e', locals())
+ with self.assertRaises(UnboundLocalError):
+ e
def testExceptionCleanupState(self):
# Make sure exception state is cleaned up as soon as the except