You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/reference/fixtures.rst
+1-17
Original file line number
Diff line number
Diff line change
@@ -19,23 +19,7 @@ to ``function`` scope.
19
19
Note that, when using the ``event_loop`` fixture, you need to interact with the event loop using methods like ``event_loop.run_until_complete``. If you want to *await* code inside your test function, you need to write a coroutine and use it as a test function. The `asyncio <#pytest-mark-asyncio>`__ marker
20
20
is used to mark coroutines that should be treated as test functions.
21
21
22
-
The ``event_loop`` fixture can be overridden in any of the standard pytest locations,
23
-
e.g. directly in the test file, or in ``conftest.py``. This allows redefining the
24
-
fixture scope, for example:
25
-
26
-
.. code-block:: python
27
-
28
-
@pytest.fixture(scope="module")
29
-
defevent_loop():
30
-
policy = asyncio.get_event_loop_policy()
31
-
loop = policy.new_event_loop()
32
-
yield loop
33
-
loop.close()
34
-
35
-
When defining multiple ``event_loop`` fixtures, you should ensure that their scopes don't overlap.
36
-
Each of the fixtures replace the running event loop, potentially without proper clean up.
37
-
This will emit a warning and likely lead to errors in your tests suite.
38
-
You can manually check for overlapping ``event_loop`` fixtures by running pytest with the ``--setup-show`` option.
22
+
If your tests require an asyncio event loop with class or module scope, apply the `asyncio_event_loop mark <./markers.html/#pytest-mark-asyncio-event-loop>`__ to the respective class or module.
39
23
40
24
If you need to change the type of the event loop, prefer setting a custom event loop policy over redefining the ``event_loop`` fixture.
0 commit comments