File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff 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+
156158If the ``pytest.mark.asyncio `` marker is applied to a test function, the ``event_loop ``
157159fixture will be requested automatically by the test function.
158160
You can’t perform that action at this time.
0 commit comments