MCPcopy Index your code
hub / github.com/python/cpython / test_run_keeps_context

Method test_run_keeps_context

Lib/test/test_asyncio/test_runners.py:387–403  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

385 self.assertEqual([1], ret)
386
387 def test_run_keeps_context(self):
388 cvar = contextvars.ContextVar("cvar", default=-1)
389
390 async def f(val):
391 old = cvar.get()
392 await asyncio.sleep(0)
393 cvar.set(val)
394 return old
395
396 async def get_context():
397 return contextvars.copy_context()
398
399 with asyncio.Runner() as runner:
400 self.assertEqual(-1, runner.run(f(1)))
401 self.assertEqual(1, runner.run(f(2)))
402
403 self.assertEqual(2, runner.run(get_context()).get(cvar))
404
405 def test_recursive_run(self):
406 async def g():

Callers

nothing calls this directly

Calls 4

fFunction · 0.50
assertEqualMethod · 0.45
runMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected