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

Method test_context_run_4

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

Source from the content-addressed store, hash-verified

141
142 @isolated_context
143 def test_context_run_4(self):
144 ctx1 = contextvars.Context()
145 ctx2 = contextvars.Context()
146 var = contextvars.ContextVar('var')
147
148 def func2():
149 self.assertIsNone(var.get(None))
150
151 def func1():
152 self.assertIsNone(var.get(None))
153 var.set('spam')
154 ctx2.run(func2)
155 self.assertEqual(var.get(None), 'spam')
156
157 cur = contextvars.copy_context()
158 self.assertEqual(len(cur), 1)
159 self.assertEqual(cur[var], 'spam')
160 return cur
161
162 returned_ctx = ctx1.run(func1)
163 self.assertEqual(ctx1, returned_ctx)
164 self.assertEqual(returned_ctx[var], 'spam')
165 self.assertIn(var, returned_ctx)
166
167 def test_context_run_5(self):
168 ctx = contextvars.Context()

Callers

nothing calls this directly

Calls 1

runMethod · 0.95

Tested by

no test coverage detected