File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1671,6 +1671,42 @@ async def run():
16711671
16721672 self .loop .run_until_complete (run ())
16731673
1674+ def test_async_gen_throw_same_aclose_coro_twice (self ):
1675+ async def async_iterate ():
1676+ yield 1
1677+ yield 2
1678+
1679+ it = async_iterate ()
1680+ nxt = it .aclose ()
1681+ with self .assertRaises (StopIteration ):
1682+ nxt .throw (GeneratorExit )
1683+
1684+ with self .assertRaisesRegex (
1685+ RuntimeError ,
1686+ r"cannot reuse already awaited aclose\(\)/athrow\(\)"
1687+ ):
1688+ nxt .throw (GeneratorExit )
1689+
1690+ def test_async_gen_throw_custom_same_aclose_coro_twice (self ):
1691+ async def async_iterate ():
1692+ yield 1
1693+ yield 2
1694+
1695+ it = async_iterate ()
1696+
1697+ class MyException (Exception ):
1698+ pass
1699+
1700+ nxt = it .aclose ()
1701+ with self .assertRaises (MyException ):
1702+ nxt .throw (MyException )
1703+
1704+ with self .assertRaisesRegex (
1705+ RuntimeError ,
1706+ r"cannot reuse already awaited aclose\(\)/athrow\(\)"
1707+ ):
1708+ nxt .throw (MyException )
1709+
16741710 def test_async_gen_aclose_twice_with_different_coros (self ):
16751711 # Regression test for https://bugs.python.org/issue39606
16761712 async def async_iterate ():
You can’t perform that action at this time.
0 commit comments