aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_asyncio/test_taskgroups.py
diff options
context:
space:
mode:
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>2022-08-04 19:27:44 +0530
committerGitHub <noreply@github.com>2022-08-04 06:57:44 -0700
commit2fef27589e44c91042c2598b5cad6c6ad0516d93 (patch)
treef89eabbb1b1eda7fe58b7628e1fce02dfd308314 /Lib/test/test_asyncio/test_taskgroups.py
parent42b102bbf9a9ae6fae8f6710202fb7afeeac277c (diff)
downloadcpython-2fef27589e44c91042c2598b5cad6c6ad0516d93.tar.gz
cpython-2fef27589e44c91042c2598b5cad6c6ad0516d93.zip
GH-95289: Always call uncancel() when parent cancellation is requested (#95602)
Co-authored-by: Guido van Rossum <guido@python.org>
Diffstat (limited to 'Lib/test/test_asyncio/test_taskgroups.py')
-rw-r--r--Lib/test/test_asyncio/test_taskgroups.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/Lib/test/test_asyncio/test_taskgroups.py b/Lib/test/test_asyncio/test_taskgroups.py
index 26fb5e466af..99498e7b36f 100644
--- a/Lib/test/test_asyncio/test_taskgroups.py
+++ b/Lib/test/test_asyncio/test_taskgroups.py
@@ -3,7 +3,7 @@
import asyncio
import contextvars
-
+import contextlib
from asyncio import taskgroups
import unittest
@@ -741,6 +741,37 @@ class TestTaskGroup(unittest.IsolatedAsyncioTestCase):
self.assertEqual(get_error_types(cm.exception), {ZeroDivisionError})
+ async def test_taskgroup_context_manager_exit_raises(self):
+ # See https://github.com/python/cpython/issues/95289
+ class CustomException(Exception):
+ pass
+
+ async def raise_exc():
+ raise CustomException
+
+ @contextlib.asynccontextmanager
+ async def database():
+ try:
+ yield
+ finally:
+ raise CustomException
+
+ async def main():
+ task = asyncio.current_task()
+ try:
+ async with taskgroups.TaskGroup() as tg:
+ async with database():
+ tg.create_task(raise_exc())
+ await asyncio.sleep(1)
+ except* CustomException as err:
+ self.assertEqual(task.cancelling(), 0)
+ self.assertEqual(len(err.exceptions), 2)
+
+ else:
+ self.fail('CustomException not raised')
+
+ await asyncio.create_task(main())
+
if __name__ == "__main__":
unittest.main()