Skip to content

Commit

Permalink
test that mark.asyncio scope is respected
Browse files Browse the repository at this point in the history
it is not, if there is a function-scoped fixture included
  • Loading branch information
minrk committed Jan 31, 2024
1 parent e92efad commit edf65a5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/markers/test_module_scope.py
Original file line number Diff line number Diff line change
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)

0 comments on commit edf65a5

Please sign in to comment.