@@ -152,15 +152,19 @@ Handling of ContextVars
152152The :mod: `contextvars ` module lets you create
153153:class: `~contextvars.ContextVar ` objects to represent task-local
154154variables. 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
161161The benefit of this is that you can set
162162:class: `~contextvars.ContextVar ` values inside a fixture, and your
163163settings 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
165169The downside is that if two fixtures are run concurrently (see
166170previous section), and both mutate the same
0 commit comments