-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Teardown of the event_loop fixture no longer replaces the event loop …
…policy. Signed-off-by: Michael Seifert <[email protected]>
- Loading branch information
Showing
4 changed files
with
41 additions
and
2 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
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,16 @@ | ||
"""Defines and sets a custom event loop policy""" | ||
import asyncio | ||
from asyncio import DefaultEventLoopPolicy, SelectorEventLoop | ||
|
||
|
||
class TestEventLoop(SelectorEventLoop): | ||
pass | ||
|
||
|
||
class TestEventLoopPolicy(DefaultEventLoopPolicy): | ||
def new_event_loop(self): | ||
return TestEventLoop() | ||
|
||
|
||
# This statement represents a code which sets a custom event loop policy | ||
asyncio.set_event_loop_policy(TestEventLoopPolicy()) |
16 changes: 16 additions & 0 deletions
16
tests/respect_event_loop_policy/test_respects_event_loop_policy.py
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,16 @@ | ||
"""Tests that any externally provided event loop policy remains unaltered.""" | ||
import asyncio | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_uses_loop_provided_by_custom_policy(): | ||
"""Asserts that test cases use the event loop provided by the custom event loop policy""" | ||
assert type(asyncio.get_event_loop()).__name__ == "TestEventLoop" | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_custom_policy_is_not_overwritten(): | ||
"""Asserts that any custom event loop policy stays the same across test cases""" | ||
assert type(asyncio.get_event_loop()).__name__ == "TestEventLoop" |