Skip to content

Commit bf4ef1e

Browse files
committed
Add more checks for exception context
1 parent ea784d7 commit bf4ef1e

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

‎Lib/test/test_contextlib.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,17 @@ def ctx(reraise=False):
364364
raise TypeError()
365365
except:
366366
with ctx():
367+
self.assertIsInstance(sys.exception(), TypeError)
368+
self.assertIsInstance(sys.exception().__context__, IndexError)
367369
try:
368370
raise ValueError()
369371
except:
370372
self.assertIsInstance(sys.exception(), ValueError)
373+
self.assertIsInstance(sys.exception().__context__, TypeError)
374+
self.assertIsInstance(sys.exception().__context__.__context__, IndexError)
371375
1/0
372376
self.assertIsInstance(sys.exception(), TypeError)
377+
self.assertIsInstance(sys.exception().__context__, IndexError)
373378
self.assertIsInstance(sys.exception(), IndexError)
374379

375380
try:
@@ -380,12 +385,17 @@ def ctx(reraise=False):
380385
except:
381386
with self.assertRaises(ZeroDivisionError):
382387
with ctx(reraise=True):
388+
self.assertIsInstance(sys.exception(), TypeError)
389+
self.assertIsInstance(sys.exception().__context__, IndexError)
383390
try:
384391
raise ValueError()
385392
except:
386393
self.assertIsInstance(sys.exception(), ValueError)
394+
self.assertIsInstance(sys.exception().__context__, TypeError)
395+
self.assertIsInstance(sys.exception().__context__.__context__, IndexError)
387396
1/0
388397
self.assertIsInstance(sys.exception(), TypeError)
398+
self.assertIsInstance(sys.exception().__context__, IndexError)
389399
self.assertIsInstance(sys.exception(), IndexError)
390400

391401
def _create_contextmanager_attribs(self):

0 commit comments

Comments
 (0)