Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support parametrized event_loop fixture (#278)
- Loading branch information
Showing
3 changed files
with
146 additions
and
115 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,31 @@ | ||
import asyncio | ||
|
||
import pytest | ||
|
||
TESTS_COUNT = 0 | ||
|
||
|
||
def teardown_module(): | ||
# parametrized 2 * 2 times: 2 for 'event_loop' and 2 for 'fix' | ||
assert TESTS_COUNT == 4 | ||
|
||
|
||
@pytest.fixture(scope="module", params=[1, 2]) | ||
def event_loop(request): | ||
request.param | ||
loop = asyncio.new_event_loop() | ||
yield loop | ||
loop.close() | ||
|
||
|
||
@pytest.fixture(params=["a", "b"]) | ||
async def fix(request): | ||
await asyncio.sleep(0) | ||
return request.param | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_parametrized_loop(fix): | ||
await asyncio.sleep(0) | ||
global TESTS_COUNT | ||
TESTS_COUNT += 1 |