diff options
| author | Yury Selivanov <yury@magic.io> | 2018-06-07 20:31:26 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-07 20:31:26 -0400 |
| commit | 52698c7ad9eae9feb35839fde17a7d1da8036a9b (patch) | |
| tree | 1db0d329f430f5eda34575454d35b0b7e5570249 /Lib/test/test_contextlib_async.py | |
| parent | 378c53cc3187dba57c7560ccc2557f516c8a7bc8 (diff) | |
| download | cpython-git-52698c7ad9eae9feb35839fde17a7d1da8036a9b.tar.gz | |
bpo-33786: Fix asynchronous generators to handle GeneratorExit in athrow() (GH-7467)
Diffstat (limited to 'Lib/test/test_contextlib_async.py')
| -rw-r--r-- | Lib/test/test_contextlib_async.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_contextlib_async.py b/Lib/test/test_contextlib_async.py index 355955f9ab..39dcd9b364 100644 --- a/Lib/test/test_contextlib_async.py +++ b/Lib/test/test_contextlib_async.py @@ -36,6 +36,28 @@ class TestAbstractAsyncContextManager(unittest.TestCase): async with manager as context: self.assertIs(manager, context) + @_async_test + async def test_async_gen_propagates_generator_exit(self): + # A regression test for https://bugs.python.org/issue33786. + + @asynccontextmanager + async def ctx(): + yield + + async def gen(): + async with ctx(): + yield 11 + + ret = [] + exc = ValueError(22) + with self.assertRaises(ValueError): + async with ctx(): + async for val in gen(): + ret.append(val) + raise exc + + self.assertEqual(ret, [11]) + def test_exit_is_abstract(self): class MissingAexit(AbstractAsyncContextManager): pass |
