Skip to content

Commit b89b34d

Browse files
committed
this time for sure...
1 parent d63783c commit b89b34d

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

docs/source/reference.rst

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,19 @@ Handling of ContextVars
152152
The :mod:`contextvars` module lets you create
153153
:class:`~contextvars.ContextVar` objects to represent task-local
154154
variables. Normally, in Trio, each task gets its own
155-
:class:`~contextvars.Context`, so that :class:`~ContextVar` mutations
156-
are only visible to the task that performs them. But pytest-trio
157-
overrides this, and for each test it uses a single
158-
:class:`~contextvars.Context` which is shared by all fixtures and the
159-
test function itself.
155+
:class:`~contextvars.Context`, so that changes to
156+
:class:`~contextvars.ContextVar` objects are only visible inside the
157+
task that performs them. But pytest-trio overrides this, and for each
158+
test it uses a single :class:`~contextvars.Context` which is shared by
159+
all fixtures and the test function itself.
160160

161161
The benefit of this is that you can set
162162
:class:`~contextvars.ContextVar` values inside a fixture, and your
163163
settings will be visible in dependent fixtures and the test itself.
164+
For example, `trio-asyncio <https://trio-asyncio.readthedocs.io/>`__
165+
uses a :class:`~contextvars.ContextVar` to hold the current asyncio
166+
loop object, so this lets you open a loop inside a fixture and then
167+
use it inside other fixtures or the test itself.
164168

165169
The downside is that if two fixtures are run concurrently (see
166170
previous section), and both mutate the same

0 commit comments

Comments
 (0)