Skip to content

Commit 1d26ee1

Browse files
committed
Add taskgroup tests
1 parent f5816da commit 1d26ee1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Lib/test/test_asyncio/test_taskgroups.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import asyncio
5+
import contextvars
56

67
from asyncio import taskgroups
78
import unittest
@@ -708,6 +709,23 @@ async def coro():
708709
t = g.create_task(coro(), name="yolo")
709710
self.assertEqual(t.get_name(), "yolo")
710711

712+
async def test_taskgroup_task_context(self):
713+
cvar = contextvars.ContextVar('cvar')
714+
715+
async def coro(val):
716+
await asyncio.sleep(0)
717+
cvar.set(val)
718+
719+
async with taskgroups.TaskGroup() as g:
720+
ctx = contextvars.copy_context()
721+
self.assertIsNone(ctx.get(cvar))
722+
t1 = g.create_task(coro(1), context=ctx)
723+
await t1
724+
self.assertEqual(1, ctx.get(cvar))
725+
t2 = g.create_task(coro(2), context=ctx)
726+
await t2
727+
self.assertEqual(2, ctx.get(cvar))
728+
711729

712730
if __name__ == "__main__":
713731
unittest.main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy