Skip to content

Commit 08952ee

Browse files
committed
docs: Provide an example for redefining the event_loop fixture rather than for setting a custom event loop.
Signed-off-by: Michael Seifert <[email protected]>
1 parent 8eaaebe commit 08952ee

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

README.rst

+8-6
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,21 @@ for treating test functions like coroutines.
140140
resp = event_loop.run_until_complete(http_client(url))
141141
assert b"HTTP/1.1 200 OK" in resp
142142
143-
This fixture can be easily overridden in any of the standard pytest locations
144-
(e.g. directly in the test file, or in ``conftest.py``) to use a non-default
145-
event loop. This will take effect even if you're using the
146-
``pytest.mark.asyncio`` marker and not the ``event_loop`` fixture directly.
143+
The ``event_loop`` fixture can be overridden in any of the standard pytest locations,
144+
e.g. directly in the test file, or in ``conftest.py``. This allows redefining the
145+
fixture scope, for example:
147146

148147
.. code-block:: python
149148
150-
@pytest.fixture
149+
@pytest.fixture(scope="session")
151150
def event_loop():
152-
loop = MyCustomLoop()
151+
policy = asyncio.get_event_loop_policy()
152+
loop = policy.new_event_loop()
153153
yield loop
154154
loop.close()
155155
156+
If you need to change the type of the event loop, prefer setting a custom event loop policy over redefining the ``event_loop`` fixture.
157+
156158
If the ``pytest.mark.asyncio`` marker is applied to a test function, the ``event_loop``
157159
fixture will be requested automatically by the test function.
158160

0 commit comments

Comments
 (0)