8000 bpo-46442: improve testExceptionCleanupNames by yellowdusk1590 · Pull Request #30758 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-46442: improve testExceptionCleanupNames #30758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,15 +671,27 @@ def test_str(self):
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
Expand Down
0