Skip to content

Commit 876cc2a

Browse files
committed
update docs/changelog
1 parent 2d9bb86 commit 876cc2a

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

changelog/10839.deprecation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Synchronous tests that request an asynchronous fixture will now give a DeprecationWarning. This will introduce warnings in several pytest plugins that handle async tests/fixtures and for some users with custom setups. For guidance on how to manage this see :ref:`sync-test-async-fixture`.
1+
Requesting an asynchronous fixture without a `pytest_fixture_setup` to handle it will now give a DeprecationWarning. This most commonly happens if a sync test requests an async fixture. This should have no effect on a majority of users with async tests or fixtures, but may affect non-standard hook setups or ``autouse=True``. For guidance on how to work around this warning see :ref:`sync-test-async-fixture`.

doc/en/deprecations.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ sync test depending on async fixture
2424

2525
Pytest has for a long time given an error when encountering an asynchronous test function, prompting the user to install
2626
a plugin that can handle it. It has not given any errors if you have an asynchronous fixture that's depended on by a
27-
synchronous test. This is a problem even if you do have a plugin installed for handling async tests, as they may require
27+
synchronous test. If the fixture was an async function you did get an "unawaited coroutine" warning, but for async yield fixtures you didn't even get that.
28+
This is a problem even if you do have a plugin installed for handling async tests, as they may require
2829
special decorators for async fixtures to be handled, and some may not robustly handle if a user accidentally requests an
2930
async fixture from their sync tests. Fixture values being cached can make this even more unintuitive, where everything will
3031
"work" if the fixture is first requested by an async test, and then requested by a synchronous test.
3132

3233
Unfortunately there is no 100% reliable method of identifying when a user has made a mistake, versus when they expect an
33-
unawaited object from their fixture that they will handle - either on their own, or by a plugin. To suppress this warning
34+
unawaited object from their fixture that they will handle on their own. To suppress this warning
3435
when you in fact did intend to handle this you can wrap your async fixture in a synchronous fixture:
3536

3637
.. code-block:: python
@@ -67,7 +68,10 @@ should be changed to
6768
def test_foo(unawaited_fixture):
6869
assert 1 == asyncio.run(unawaited_fixture)
6970
70-
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. Plugins that handle async may want to introduce helpers to make that easier in scenarios where that might be wanted, e.g. if setting up a database in an asynchronous way, or the user may opt to make their test async even though it might not strictly need to be.
71+
72+
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.
73+
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 has some support for sync test + async fixtures currently.
7175

7276

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

0 commit comments

Comments
 (0)