Skip to content

Commit 5894656

Browse files
committed
docs: Added how-to guide on changing the event loop scope of a fixture.
Signed-off-by: Michael Seifert <[email protected]>
1 parent 4716526 commit 5894656

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
===============================================
2+
How to change the event loop scope of a fixture
3+
===============================================
4+
The event loop scope of an asynchronous fixture is specified via the *loop_scope* keyword argument to :ref:`pytest_asyncio.fixture <decorators/pytest_asyncio_fixture>`. The following fixture runs in the module-scoped event loop:
5+
6+
.. include:: change_fixture_loop_example.py
7+
:code: python
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import asyncio
2+
3+
import pytest
4+
5+
import pytest_asyncio
6+
7+
8+
@pytest_asyncio.fixture(loop_scope="module")
9+
async def current_loop():
10+
return asyncio.get_running_loop()
11+
12+
13+
@pytest.mark.asyncio(loop_scope="module")
14+
async def test_runs_in_module_loop(current_loop):
15+
assert current_loop is asyncio.get_running_loop()

docs/source/how-to-guides/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ How-To Guides
55
.. toctree::
66
:hidden:
77

8+
change_fixture_loop
89
run_class_tests_in_same_loop
910
run_module_tests_in_same_loop
1011
run_package_tests_in_same_loop

docs/source/reference/decorators/index.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _decorators/pytest_asyncio_fixture:
2+
13
==========
24
Decorators
35
==========

0 commit comments

Comments
 (0)