Skip to content

Commit 48cad08

Browse files
committed
[docs] Added how-to guide for testing with multiple loops.
Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
1 parent 0352780 commit 48cad08

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

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+
multiple_loops
89
uvloop
910

1011
This section of the documentation provides code snippets and recipes to accomplish specific tasks with pytest-asyncio.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
======================================
2+
How to test with different event loops
3+
======================================
4+
5+
Parametrizing the *event_loop_policy* fixture parametrizes all async tests. The following example causes all async tests to run multiple times, once for each event loop in the fixture parameters:
6+
7+
.. include:: multiple_loops_example.py
8+
:code: python
9+
10+
You may choose to limit the scope of the fixture to *package,* *module,* or *class,* if you only want a subset of your tests to run with different event loops.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import asyncio
2+
from asyncio import DefaultEventLoopPolicy
3+
4+
import pytest
5+
6+
7+
class CustomEventLoopPolicy(DefaultEventLoopPolicy):
8+
pass
9+
10+
11+
@pytest.fixture(
12+
scope="session",
13+
params=(
14+
CustomEventLoopPolicy(),
15+
CustomEventLoopPolicy(),
16+
),
17+
)
18+
def event_loop_policy(request):
19+
return request.param
20+
21+
22+
@pytest.mark.asyncio
23+
async def test_uses_custom_event_loop_policy():
24+
assert isinstance(asyncio.get_event_loop_policy(), CustomEventLoopPolicy)

0 commit comments

Comments
 (0)