Skip to content

Commit b0349c2

Browse files
committed
fix remaining tests.
1 parent e51cd4d commit b0349c2

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

pytest_asyncio/plugin.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
PytestPluginManager,
5050
)
5151

52-
from typing import Callable
5352
if sys.version_info >= (3, 10):
5453
from typing import ParamSpec
5554
else:
@@ -182,7 +181,12 @@ def fixture(
182181

183182
@functools.wraps(fixture)
184183
def inner(fixture_function: FixtureFunction[_P, _R]) -> FixtureFunction[_P, _R]:
185-
return fixture(fixture_function, loop_factory=loop_factory, loop_scope=loop_scope, **kwargs)
184+
return fixture(
185+
fixture_function,
186+
loop_factory=loop_factory,
187+
loop_scope=loop_scope,
188+
**kwargs,
189+
)
186190

187191
return inner
188192

@@ -741,10 +745,12 @@ def _synchronize_coroutine(
741745
Return a sync wrapper around a coroutine executing it in the
742746
specified runner and context.
743747
"""
748+
744749
@functools.wraps(func)
745750
def inner(*args, **kwargs):
746751
coro = func(*args, **kwargs)
747752
runner.run(coro, context=context)
753+
748754
return inner
749755

750756

@@ -792,9 +798,13 @@ def _get_marked_loop_scope(
792798
) -> _ScopeName:
793799
assert asyncio_marker.name == "asyncio"
794800
if asyncio_marker.args or (
795-
asyncio_marker.kwargs and set(asyncio_marker.kwargs) - {"loop_scope", "scope", "loop_factory"}
801+
asyncio_marker.kwargs
802+
and set(asyncio_marker.kwargs) - {"loop_scope", "scope", "loop_factory"}
796803
):
797-
raise ValueError("mark.asyncio accepts only a keyword arguments 'loop_scope' or 'loop_factory'")
804+
raise ValueError(
805+
"mark.asyncio accepts only a keyword arguments 'loop_scope' "
806+
"or 'loop_factory'"
807+
)
798808
if "scope" in asyncio_marker.kwargs:
799809
if "loop_scope" in asyncio_marker.kwargs:
800810
raise pytest.UsageError(_DUPLICATE_LOOP_SCOPE_DEFINITION_ERROR)
@@ -827,11 +837,13 @@ def _get_loop_facotry(
827837
request: FixtureRequest,
828838
) -> Callable[[], AbstractEventLoop] | None:
829839
if asyncio_mark := request._pyfuncitem.get_closest_marker("asyncio"):
840+
# The loop_factory is defined on an asyncio marker
830841
factory = asyncio_mark.kwargs.get("loop_factory", None)
831-
print(f"FACTORY {factory}")
832842
return factory
833843
else:
834-
return request.obj.__dict__.get("_loop_factory", None) # type: ignore[attr-defined]
844+
# The loop_factory is pulled in via a fixture
845+
top_request = list(request._iter_chain())[-1]._parent_request
846+
return top_request._pyfuncitem.__dict__.get("_loop_factory", None) # type: ignore[attr-defined]
835847

836848

837849
def _create_scoped_runner_fixture(scope: _ScopeName) -> Callable:

tests/test_asyncio_mark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,4 @@ async def test_with_fixture(custom_fixture):
264264
)
265265

266266
result = pytester.runpytest("--asyncio-mode=auto")
267-
result.assert_outcomes(passed=1)
267+
result.assert_outcomes(passed=2)

0 commit comments

Comments
 (0)