summaryrefslogtreecommitdiff
path: root/Lib/test/test_exceptions.py
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2019-08-25 03:44:09 -0600
committerSerhiy Storchaka <storchaka@gmail.com>2019-08-25 12:44:09 +0300
commitce6a070414ed1e1374d1e6212bfbff61b6d5d755 (patch)
tree55f9d0c54b98ad3c95e78a235668f6dbc314087b /Lib/test/test_exceptions.py
parent8371799e300475c8f9f967e900816218d3500e5d (diff)
downloadcpython-git-ce6a070414ed1e1374d1e6212bfbff61b6d5d755.tar.gz
bpo-34880: Add the LOAD_ASSERTION_ERROR opcode. (GH-15073)
Fix assert statement misbehavior if AssertionError is shadowed.
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r--Lib/test/test_exceptions.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 10c1e07646..4d1aa4bca6 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -1285,6 +1285,22 @@ class ExceptionTests(unittest.TestCase):
next(i)
next(i)
+ @unittest.skipUnless(__debug__, "Won't work if __debug__ is False")
+ def test_assert_shadowing(self):
+ # Shadowing AssertionError would cause the assert statement to
+ # misbehave.
+ global AssertionError
+ AssertionError = TypeError
+ try:
+ assert False, 'hello'
+ except BaseException as e:
+ del AssertionError
+ self.assertIsInstance(e, AssertionError)
+ self.assertEqual(str(e), 'hello')
+ else:
+ del AssertionError
+ self.fail('Expected exception')
+
class ImportErrorTests(unittest.TestCase):