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

Skip to content

Commit 82c5322

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.
1 parent 70c1646 commit 82c5322

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
@@ -671,15 +671,27 @@ def test_str(self):
671671
self.assertTrue(str(Exception('a')))
672672
self.assertTrue(str(Exception('a', 'b')))
673673

674-
def testExceptionCleanupNames(self):
674+
def test_exception_cleanup_names(self):
675675
# Make sure the local variable bound to the exception instance by
676676
# an "except" statement is only visible inside the except block.
677677
try:
678678
raise Exception()
679679
except Exception as e:
680-
self.assertTrue(e)
680+
self.assertIsInstance(e, Exception)
681+
self.assertNotIn('e', locals())
682+
with self.assertRaises(UnboundLocalError):
683+
e
684+
685+
def test_exception_cleanup_names2(self):
686+
# Make sure the cleanup doesn't break if the variable is explicitly deleted.
687+
try:
688+
raise Exception()
689+
except Exception as e:
690+
self.assertIsInstance(e, Exception)
681691
del e
682692
self.assertNotIn('e', locals())
693+
with self.assertRaises(UnboundLocalError):
694+
e
683695

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

0 commit comments

Comments
 (0)
0