mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
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 82c53229e1
)
Co-authored-by: Yellow Dusk <yellow.dusk1590@fastmail.com>
This commit is contained in:
parent
46e6aad129
commit
d4a9e34401
1 changed files with 14 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue