Skip to content

Commit 2dd829f

Browse files
committed
refactor: Removed warning when requesting a fixture named *event_loop*.
1 parent ef202eb commit 2dd829f

File tree

4 files changed

+0
-90
lines changed

4 files changed

+0
-90
lines changed

pytest_asyncio/plugin.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ class PytestAsyncioError(Exception):
7070
"""Base class for exceptions raised by pytest-asyncio"""
7171

7272

73-
class MultipleEventLoopsRequestedError(PytestAsyncioError):
74-
"""Raised when a test requests multiple asyncio event loops."""
75-
76-
7773
class Mode(str, enum.Enum):
7874
AUTO = "auto"
7975
STRICT = "strict"
@@ -808,14 +804,6 @@ def pytest_generate_tests(metafunc: Metafunc) -> None:
808804
return
809805
fixturemanager = metafunc.config.pluginmanager.get_plugin("funcmanage")
810806
assert fixturemanager is not None
811-
if "event_loop" in metafunc.fixturenames:
812-
raise MultipleEventLoopsRequestedError(
813-
_MULTIPLE_LOOPS_REQUESTED_ERROR.format(
814-
test_name=metafunc.definition.nodeid,
815-
scope=scope,
816-
scoped_loop_node=event_loop_node.nodeid,
817-
),
818-
)
819807
# Add the scoped event loop fixture to Metafunc's list of fixture names and
820808
# fixturedefs and leave the actual parametrization to pytest
821809
# The fixture needs to be appended to avoid messing up the fixture evaluation
@@ -943,18 +931,6 @@ def inner(*args, **kwargs):
943931
return inner
944932

945933

946-
_MULTIPLE_LOOPS_REQUESTED_ERROR = dedent(
947-
"""\
948-
Multiple asyncio event loops with different scopes have been requested
949-
by {test_name}. The test explicitly requests the event_loop fixture, while
950-
another event loop with {scope} scope is provided by {scoped_loop_node}.
951-
Remove "event_loop" from the requested fixture in your test to run the test
952-
in a {scope}-scoped event loop or remove the scope argument from the "asyncio"
953-
mark to run the test in a function-scoped event loop.
954-
"""
955-
)
956-
957-
958934
def pytest_runtest_setup(item: pytest.Item) -> None:
959935
marker = item.get_closest_marker("asyncio")
960936
if marker is None:

tests/markers/test_module_scope.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,28 +36,6 @@ async def test_this_runs_in_same_loop(self):
3636
result.assert_outcomes(passed=3)
3737

3838

39-
def test_raise_when_event_loop_fixture_is_requested_in_addition_to_scoped_loop(
40-
pytester: Pytester,
41-
):
42-
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
43-
pytester.makepyfile(
44-
dedent(
45-
"""\
46-
import asyncio
47-
import pytest
48-
49-
pytestmark = pytest.mark.asyncio(loop_scope="module")
50-
51-
async def test_remember_loop(event_loop):
52-
pass
53-
"""
54-
)
55-
)
56-
result = pytester.runpytest("--asyncio-mode=strict")
57-
result.assert_outcomes(errors=1)
58-
result.stdout.fnmatch_lines("*MultipleEventLoopsRequestedError: *")
59-
60-
6139
def test_asyncio_mark_respects_the_loop_policy(
6240
pytester: Pytester,
6341
):

tests/markers/test_package_scope.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,6 @@ async def test_subpackage_runs_in_different_loop():
6969
result.assert_outcomes(passed=4)
7070

7171

72-
def test_raise_when_event_loop_fixture_is_requested_in_addition_to_scoped_loop(
73-
pytester: Pytester,
74-
):
75-
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
76-
pytester.makepyfile(
77-
__init__="",
78-
test_raises=dedent(
79-
"""\
80-
import asyncio
81-
import pytest
82-
83-
@pytest.mark.asyncio(loop_scope="package")
84-
async def test_remember_loop(event_loop):
85-
pass
86-
"""
87-
),
88-
)
89-
result = pytester.runpytest("--asyncio-mode=strict")
90-
result.assert_outcomes(errors=1)
91-
result.stdout.fnmatch_lines("*MultipleEventLoopsRequestedError: *")
92-
93-
9472
def test_asyncio_mark_respects_the_loop_policy(
9573
pytester: Pytester,
9674
):

tests/markers/test_session_scope.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,28 +70,6 @@ async def test_subpackage_runs_in_same_loop():
7070
result.assert_outcomes(passed=4)
7171

7272

73-
def test_raise_when_event_loop_fixture_is_requested_in_addition_to_scoped_loop(
74-
pytester: Pytester,
75-
):
76-
pytester.makeini("[pytest]\nasyncio_default_fixture_loop_scope = function")
77-
pytester.makepyfile(
78-
__init__="",
79-
test_raises=dedent(
80-
"""\
81-
import asyncio
82-
import pytest
83-
84-
@pytest.mark.asyncio(loop_scope="session")
85-
async def test_remember_loop(event_loop):
86-
pass
87-
"""
88-
),
89-
)
90-
result = pytester.runpytest("--asyncio-mode=strict")
91-
result.assert_outcomes(errors=1)
92-
result.stdout.fnmatch_lines("*MultipleEventLoopsRequestedError: *")
93-
94-
9573
def test_asyncio_mark_respects_the_loop_policy(
9674
pytester: Pytester,
9775
):

0 commit comments

Comments
 (0)