Skip to content

Commit f434c27

Browse files
committed
be more explicit about the downside of async autouse fixtures
1 parent 49c140d commit f434c27

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

doc/en/deprecations.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,18 @@ should be changed to
7171
7272
You can also make use of `pytest_fixture_setup` to handle the coroutine/asyncgen before pytest sees it - this is the way current async pytest plugins handle it.
7373

74-
If a user has an async fixture with ``autouse=True`` in their ``conftest.py``, or in a file where they also have synchronous tests, they will also get this warning. We strongly recommend against this practice, and they should restructure their testing infrastructure so the fixture is synchronous or to separate the fixture from their synchronous tests. Note that the `anyio pytest plugin <https://anyio.readthedocs.io/en/stable/testing.html>`_ has some support for sync test + async fixtures currently.
74+
If a user has an async fixture with ``autouse=True`` in their ``conftest.py``, or in a file
75+
containing both synchronous tests and the fixture, they will receive this warning.
76+
Unless you're using a plugin that specifically handles async fixtures
77+
with synchronous tests, we strongly recommend against this practice.
78+
It can lead to unpredictable behavior (with larger scopes, it may appear to "work" if an async
79+
test is the first to request the fixture, due to value caching) and will generate
80+
unawaited-coroutine runtime warnings (but only for non-yield fixtures).
81+
Additionally, it creates ambiguity for other developers about whether the fixture is intended to perform
82+
setup for synchronous tests.
83+
84+
The `anyio pytest plugin <https://anyio.readthedocs.io/en/stable/testing.html>`_ supports
85+
synchronous tests with async fixtures, though certain limitations apply.
7586

7687

7788
.. _import-or-skip-import-error:

0 commit comments

Comments
 (0)