From 8ce148edcc41e576a1810937cbd56059f7d2d91a Mon Sep 17 00:00:00 2001 From: Yiyang Zhan <pon.zhan@gmail.com> Date: Thu, 29 Sep 2022 20:05:40 +0900 Subject: [PATCH] [coverage] Add an asynchronous generator test Cover the error condition of 'asynchronous generator is already running' --- Lib/test/test_asyncgen.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Lib/test/test_asyncgen.py b/Lib/test/test_asyncgen.py index f6184c0cab4694..0421efdbf9dac9 100644 --- a/Lib/test/test_asyncgen.py +++ b/Lib/test/test_asyncgen.py @@ -378,6 +378,19 @@ async def async_gen_wrapper(): self.compare_generators(sync_gen_wrapper(), async_gen_wrapper()) + def test_async_gen_exception_12(self): + async def gen(): + await anext(me) + yield 123 + + me = gen() + ai = me.__aiter__() + an = ai.__anext__() + + with self.assertRaisesRegex(RuntimeError, + r'anext\(\): asynchronous generator is already running'): + an.__next__() + def test_async_gen_3_arg_deprecation_warning(self): async def gen(): yield 123