diff options
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r-- | Lib/test/test_exceptions.py | 16 |
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): |