Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test that mark.asyncio scope is respected #770

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/markers/test_module_scope.py
Expand Up @@ -344,3 +344,39 @@ async def test_does_not_fail(sets_event_loop_to_none, n):
)
result = pytester.runpytest("--asyncio-mode=strict")
result.assert_outcomes(passed=2)


def test_asyncio_mark_module_level_loop_reused(
pytester: Pytester,
):
pytester.makepyfile(
dedent(
"""\
import pytest
import asyncio
import pytest_asyncio

@pytest_asyncio.fixture(scope="module")
async def module_loop():
return asyncio.get_running_loop()

@pytest_asyncio.fixture(scope="function")
async def function_loop():
return asyncio.get_running_loop()

@pytest.mark.asyncio(scope="function")
async def test_function_loop(module_loop, function_loop):
assert asyncio.get_running_loop() is function_loop

@pytest.mark.asyncio(scope="module")
async def test_module_loop(module_loop):
assert asyncio.get_running_loop() is module_loop

@pytest.mark.asyncio(scope="module")
async def test_module_loop_function_fixture(module_loop, function_loop):
assert asyncio.get_running_loop() is module_loop
"""
)
)
result = pytester.runpytest("--asyncio-mode=strict")
result.assert_outcomes(passed=3)