File tree 1 file changed +8
-6
lines changed
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.
140
140
resp = event_loop.run_until_complete(http_client(url))
141
141
assert b " HTTP/1.1 200 OK" in resp
142
142
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:
147
146
148
147
.. code-block :: python
149
148
150
- @pytest.fixture
149
+ @pytest.fixture ( scope = " session " )
151
150
def event_loop ():
152
- loop = MyCustomLoop()
151
+ policy = asyncio.get_event_loop_policy()
152
+ loop = policy.new_event_loop()
153
153
yield loop
154
154
loop.close()
155
155
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
+
156
158
If the ``pytest.mark.asyncio `` marker is applied to a test function, the ``event_loop ``
157
159
fixture will be requested automatically by the test function.
158
160
You can’t perform that action at this time.
0 commit comments