summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_exceptions.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_exceptions.py')
-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 531b9c9..5932b9d 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -671,15 +671,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