MCPcopy Create free account
hub / github.com/MagicStack/contextvars / test_context_copy_1

Method test_context_copy_1

tests/test_basics.py:315–338  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

313 self.assertEqual(c.get(), [])
314
315 def test_context_copy_1(self):
316 ctx1 = contextvars.Context()
317 c = contextvars.ContextVar('c', default=42)
318
319 def ctx1_fun():
320 c.set(10)
321
322 ctx2 = ctx1.copy()
323 self.assertEqual(ctx2[c], 10)
324
325 c.set(20)
326 self.assertEqual(ctx1[c], 20)
327 self.assertEqual(ctx2[c], 10)
328
329 ctx2.run(ctx2_fun)
330 self.assertEqual(ctx1[c], 20)
331 self.assertEqual(ctx2[c], 30)
332
333 def ctx2_fun():
334 self.assertEqual(c.get(), 10)
335 c.set(30)
336 self.assertEqual(c.get(), 30)
337
338 ctx1.run(ctx1_fun)
339
340 @isolated_context
341 def test_context_threads_1(self):

Callers

nothing calls this directly

Calls 1

runMethod · 0.95

Tested by

no test coverage detected