-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Added how-to guide for testing with multiple loops.
Signed-off-by: Michael Seifert <[email protected]>
- Loading branch information
Showing
3 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
====================================== | ||
How to test with different event loops | ||
====================================== | ||
|
||
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: | ||
|
||
.. include:: multiple_loops_example.py | ||
:code: python | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import asyncio | ||
from asyncio import DefaultEventLoopPolicy | ||
|
||
import pytest | ||
|
||
|
||
class CustomEventLoopPolicy(DefaultEventLoopPolicy): | ||
pass | ||
|
||
|
||
@pytest.fixture( | ||
scope="session", | ||
params=( | ||
CustomEventLoopPolicy(), | ||
CustomEventLoopPolicy(), | ||
), | ||
) | ||
def event_loop_policy(request): | ||
return request.param | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_uses_custom_event_loop_policy(): | ||
assert isinstance(asyncio.get_event_loop_policy(), CustomEventLoopPolicy) |