Skip to content

Commit 70ed7a8

Browse files
committed
Add a failing test for issue 29587.
1 parent e3dfb9b commit 70ed7a8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Lib/test/test_generators.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,23 @@ def g():
316316
self.assertEqual(cm.exception.value.value, 2)
317317

318318

319+
class GeneratorThrowTest(unittest.TestCase):
320+
321+
def test_exception_context_set(self):
322+
def f():
323+
try:
324+
raise KeyError('a')
325+
except Exception:
326+
yield
327+
328+
gen = f()
329+
gen.send(None)
330+
with self.assertRaises(ValueError) as cm:
331+
gen.throw(ValueError)
332+
context = cm.exception.__context__
333+
self.assertEqual((type(context), context.args), (KeyError, ('a',)))
334+
335+
319336
class YieldFromTests(unittest.TestCase):
320337
def test_generator_gi_yieldfrom(self):
321338
def a():

0 commit comments

Comments
 (0)