Skip to content

Commit dd6f901

Browse files
committed
bpo-29587: Add another test for the fix.
1 parent 1ce5841 commit dd6f901

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Lib/test/test_generators.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,28 @@ def f():
332332
context = cm.exception.__context__
333333
self.assertEqual((type(context), context.args), (KeyError, ('a',)))
334334

335+
def test_exception_context_with_yield_inside_generator(self):
336+
# Check that the context is also available from inside the generator
337+
# with yield, as opposed to outside.
338+
def f():
339+
try:
340+
raise KeyError('a')
341+
except Exception:
342+
try:
343+
yield
344+
except Exception as exc:
345+
self.assertEqual(type(exc), ValueError)
346+
context = exc.__context__
347+
self.assertEqual((type(context), context.args),
348+
(KeyError, ('a',)))
349+
yield 'b'
350+
351+
gen = f()
352+
gen.send(None)
353+
actual = gen.throw(ValueError)
354+
# This ensures that the assertions inside were executed.
355+
self.assertEqual(actual, 'b')
356+
335357
def test_exception_context_with_yield_from(self):
336358
def f():
337359
yield

0 commit comments

Comments
 (0)