bpo-34880: Add the LOAD_ASSERTION_ERROR opcode. (GH-15073)
Fix assert statement misbehavior if AssertionError is shadowed.
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 10c1e07..4d1aa4b 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -1285,6 +1285,22 @@
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):