diff options
author | Kinshuk Dua <kinshukdua@gmail.com> | 2022-01-27 10:24:48 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-27 10:24:48 (GMT) |
commit | 08c0ed2d9c0d01ad1a5adc0787bc75e4e90cbb85 (patch) | |
tree | bcb78c4f5b61fb3345fd7e711fb638f7c823457f /Lib | |
parent | 606e496dd6e2ace298532da200169124c26ae0f2 (diff) | |
download | cpython-08c0ed2d9c0d01ad1a5adc0787bc75e4e90cbb85.zip cpython-08c0ed2d9c0d01ad1a5adc0787bc75e4e90cbb85.tar.gz cpython-08c0ed2d9c0d01ad1a5adc0787bc75e4e90cbb85.tar.bz2 |
bpo-23556: [doc] Fix inaccuracy in documentation for raise without args. Improve tests for context in nested except handlers. (GH-29236)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_raise.py | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/Lib/test/test_raise.py b/Lib/test/test_raise.py index 8225504..5936d75 100644 --- a/Lib/test/test_raise.py +++ b/Lib/test/test_raise.py @@ -303,7 +303,7 @@ class TestContext(unittest.TestCase): except: raise OSError() except OSError as e: - self.assertEqual(e.__context__, context) + self.assertIs(e.__context__, context) else: self.fail("No exception raised") @@ -315,7 +315,7 @@ class TestContext(unittest.TestCase): except: raise OSError() except OSError as e: - self.assertNotEqual(e.__context__, context) + self.assertIsNot(e.__context__, context) self.assertIsInstance(e.__context__, context) else: self.fail("No exception raised") @@ -328,7 +328,7 @@ class TestContext(unittest.TestCase): except: raise OSError except OSError as e: - self.assertNotEqual(e.__context__, context) + self.assertIsNot(e.__context__, context) self.assertIsInstance(e.__context__, context) else: self.fail("No exception raised") @@ -415,6 +415,22 @@ class TestContext(unittest.TestCase): except NameError as e: self.assertIsNone(e.__context__.__context__) + def test_not_last(self): + # Context is not necessarily the last exception + context = Exception("context") + try: + raise context + except Exception: + try: + raise Exception("caught") + except Exception: + pass + try: + raise Exception("new") + except Exception as exc: + raised = exc + self.assertIs(raised.__context__, context) + def test_3118(self): # deleting the generator caused the __context__ to be cleared def gen(): |