From edf65a5f40365d35576580dd8061c42d6152c377 Mon Sep 17 00:00:00 2001 From: Min RK Date: Wed, 31 Jan 2024 13:16:39 +0100 Subject: [PATCH] test that mark.asyncio scope is respected it is not, if there is a function-scoped fixture included --- tests/markers/test_module_scope.py | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/markers/test_module_scope.py b/tests/markers/test_module_scope.py index cf6b2f60..c43e5852 100644 --- a/tests/markers/test_module_scope.py +++ b/tests/markers/test_module_scope.py @@ -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)