Skip to content

Commit 1821542

Browse files
committed
[docs] Explain that scopes of event_loop fixtures should not overlap.
The example for overriding event loop scopes now uses a module scope rather than a session scope. Due to the constraint that event_loop fixture scopes should not overlap, a session-scoped fixture is usually not that helpful. Addresses #531 Signed-off-by: Michael Seifert <[email protected]>
1 parent 5890189 commit 1821542

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

docs/source/reference/fixtures.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@ fixture scope, for example:
2525

2626
.. code-block:: python
2727
28-
@pytest.fixture(scope="session")
28+
@pytest.fixture(scope="module")
2929
def event_loop():
3030
policy = asyncio.get_event_loop_policy()
3131
loop = policy.new_event_loop()
3232
yield loop
3333
loop.close()
3434
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.
39+
3540
If you need to change the type of the event loop, prefer setting a custom event loop policy over redefining the ``event_loop`` fixture.
3641

3742
If the ``pytest.mark.asyncio`` decorator is applied to a test function, the ``event_loop``

0 commit comments

Comments
 (0)