File tree 2 files changed +18
-3
lines changed
2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -731,7 +731,19 @@ def pytest_generate_tests(metafunc: Metafunc) -> None:
731
731
event_loop_fixture_id = event_loop_node .stash .get (_event_loop_fixture_id , None )
732
732
733
733
if event_loop_fixture_id :
734
- if "event_loop" in metafunc .fixturenames :
734
+ collectors = _iter_collectors (metafunc .definition )
735
+ collector_event_loop_fixture_ids = map (
736
+ lambda c : c .stash .get (_event_loop_fixture_id , None ), # type: ignore
737
+ collectors ,
738
+ )
739
+ possible_event_loop_fixture_ids = {"event_loop" } | set (
740
+ collector_event_loop_fixture_ids
741
+ )
742
+ used_fixture_ids = {event_loop_fixture_id , * metafunc .fixturenames }
743
+ used_event_loop_fixture_ids = possible_event_loop_fixture_ids .intersection (
744
+ used_fixture_ids
745
+ )
746
+ if len (used_event_loop_fixture_ids ) > 1 :
735
747
raise MultipleEventLoopsRequestedError (
736
748
_MULTIPLE_LOOPS_REQUESTED_ERROR .format (
737
749
test_name = metafunc .definition .nodeid ,
Original file line number Diff line number Diff line change 1
1
from textwrap import dedent
2
2
3
+ import pytest
3
4
from pytest import Pytester
4
5
5
6
7
+ @pytest .mark .parametrize ("autouse_fixture_scope" , ("function" , "module" ))
6
8
def test_autouse_fixture_in_different_scope_triggers_multiple_event_loop_error (
7
9
pytester : Pytester ,
10
+ autouse_fixture_scope : str ,
8
11
):
9
12
pytester .makepyfile (
10
13
dedent (
11
- """\
14
+ f """\
12
15
import asyncio
13
16
import pytest
14
17
import pytest_asyncio
15
18
16
19
loop: asyncio.AbstractEventLoop
17
20
18
- @pytest_asyncio.fixture(autouse=True)
21
+ @pytest_asyncio.fixture(autouse=True, scope=" { autouse_fixture_scope } " )
19
22
async def autouse_fixture():
20
23
pass
21
24
You can’t perform that action at this time.
0 commit comments