Skip to content

Commit

Permalink
Add taskgroup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Mar 14, 2022
1 parent f5816da commit 1d26ee1
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Lib/test/test_asyncio/test_taskgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import asyncio
import contextvars

from asyncio import taskgroups
import unittest
Expand Down Expand Up @@ -708,6 +709,23 @@ async def coro():
t = g.create_task(coro(), name="yolo")
self.assertEqual(t.get_name(), "yolo")

async def test_taskgroup_task_context(self):
cvar = contextvars.ContextVar('cvar')

async def coro(val):
await asyncio.sleep(0)
cvar.set(val)

async with taskgroups.TaskGroup() as g:
ctx = contextvars.copy_context()
self.assertIsNone(ctx.get(cvar))
t1 = g.create_task(coro(1), context=ctx)
await t1
self.assertEqual(1, ctx.get(cvar))
t2 = g.create_task(coro(2), context=ctx)
await t2
self.assertEqual(2, ctx.get(cvar))


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

0 comments on commit 1d26ee1

Please sign in to comment.