Debian Codegraph @

tests/markers/test_mixed_scope.py

raw
1 from __future__ import annotations
2
3 from textwrap import dedent
4
5 from pytest import Pytester
6
7
8 def test_function_scoped_loop_restores_previous_loop_scope(pytester: Pytester):
9 pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
10 pytester.makepyfile(dedent("""\
11 import asyncio
12 import pytest
13
14
15 module_loop: asyncio.AbstractEventLoop
16
17 @pytest.mark.asyncio(loop_scope="module")
18 async def test_remember_loop():
19 global module_loop
20 module_loop = asyncio.get_running_loop()
21
22 @pytest.mark.asyncio(loop_scope="function")
23 async def test_with_function_scoped_loop():
24 pass
25
26 @pytest.mark.asyncio(loop_scope="module")
27 async def test_runs_in_same_loop():
28 global module_loop
29 assert asyncio.get_running_loop() is module_loop
30 """))
31 result = pytester.runpytest("--asyncio-mode=strict")
32 result.assert_outcomes(passed=3)