8000 bpo-46442: improve and rename testExceptionCleanupNames (GH-30758) · python/cpython@d4a9e34 · GitHub
[go: up one dir, main page]

Skip to content

Commit d4a9e34

Browse files
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 82c5322) Co-authored-by: Yellow Dusk <yellow.dusk1590@fastmail.com>
1 parent 46e6aad commit d4a9e34

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Lib/test/test_exceptions.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,15 +648,27 @@ def test_str(self):
648648
self.assertTrue(str(Exception('a')))
649649
self.assertTrue(str(Exception('a', 'b')))
650650

651-
def testExceptionCleanupNames(self):
651+
def test_exception_cleanup_names(self):
652652
# Make sure the local variable bound to the exception instance by
653653
# an "except" statement is only visible inside the except block.
654654
try:
655655
raise Exception()
656656
except Exception as e:
657-
self.assertTrue(e)
657+
self.assertIsInstance(e, Exception)
658+
self.assertNotIn('e', locals())
659+
with self.assertRaises(UnboundLocalError):
660+
e
661+
662+
def test_exception_cleanup_names2(self):
663+
# Make sure the cleanup doesn't break if the variable is explicitly deleted.
664+
try:
665+
raise Exception()
666+
except Exception as e:
667+
self.assertIsInstance(e, Exception)
658668
del e
659669
self.assertNotIn('e', locals())
670+
with self.assertRaises(UnboundLocalError):
671+
e
660672

661673
def testExceptionCleanupState(self):
662674
# Make sure exception state is cleaned up as soon as the except

0 commit comments

Comments
 (0)
0