Skip to content

Commit 10d17bc

Browse files
add test
1 parent 14a5674 commit 10d17bc

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

Lib/test/test_asyncio/test_taskgroups.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import asyncio
55
import contextvars
6-
6+
import contextlib
77
from asyncio import taskgroups
88
import unittest
99

@@ -741,6 +741,35 @@ async def coro2(g):
741741

742742
self.assertEqual(get_error_types(cm.exception), {ZeroDivisionError})
743743

744+
async def test_taskgroup_context_manager_exit_raises(self):
745+
# See https://github.com/python/cpython/issues/95289
746+
class CustomException(Exception):
747+
pass
748+
749+
async def raise_exc():
750+
raise CustomException
751+
752+
@contextlib.asynccontextmanager
753+
async def database():
754+
try:
755+
yield
756+
finally:
757+
raise CustomException
758+
759+
async def main():
760+
task = asyncio.current_task()
761+
try:
762+
async with taskgroups.TaskGroup() as tg:
763+
async with database():
764+
tg.create_task(raise_exc())
765+
await asyncio.sleep(1)
766+
except* CustomException:
767+
self.assertEqual(task.cancelling(), 0)
768+
else:
769+
self.fail('CustomException not raised')
770+
771+
await asyncio.create_task(main())
772+
744773

745774
if __name__ == "__main__":
746775
unittest.main()

0 commit comments

Comments
 (0)