|
49 | 49 | PytestPluginManager, |
50 | 50 | ) |
51 | 51 |
|
52 | | -from typing import Callable |
53 | 52 | if sys.version_info >= (3, 10): |
54 | 53 | from typing import ParamSpec |
55 | 54 | else: |
@@ -182,7 +181,12 @@ def fixture( |
182 | 181 |
|
183 | 182 | @functools.wraps(fixture) |
184 | 183 | 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 | + ) |
186 | 190 |
|
187 | 191 | return inner |
188 | 192 |
|
@@ -741,10 +745,12 @@ def _synchronize_coroutine( |
741 | 745 | Return a sync wrapper around a coroutine executing it in the |
742 | 746 | specified runner and context. |
743 | 747 | """ |
| 748 | + |
744 | 749 | @functools.wraps(func) |
745 | 750 | def inner(*args, **kwargs): |
746 | 751 | coro = func(*args, **kwargs) |
747 | 752 | runner.run(coro, context=context) |
| 753 | + |
748 | 754 | return inner |
749 | 755 |
|
750 | 756 |
|
@@ -792,9 +798,13 @@ def _get_marked_loop_scope( |
792 | 798 | ) -> _ScopeName: |
793 | 799 | assert asyncio_marker.name == "asyncio" |
794 | 800 | 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"} |
796 | 803 | ): |
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 | + ) |
798 | 808 | if "scope" in asyncio_marker.kwargs: |
799 | 809 | if "loop_scope" in asyncio_marker.kwargs: |
800 | 810 | raise pytest.UsageError(_DUPLICATE_LOOP_SCOPE_DEFINITION_ERROR) |
@@ -827,11 +837,13 @@ def _get_loop_facotry( |
827 | 837 | request: FixtureRequest, |
828 | 838 | ) -> Callable[[], AbstractEventLoop] | None: |
829 | 839 | if asyncio_mark := request._pyfuncitem.get_closest_marker("asyncio"): |
| 840 | + # The loop_factory is defined on an asyncio marker |
830 | 841 | factory = asyncio_mark.kwargs.get("loop_factory", None) |
831 | | - print(f"FACTORY {factory}") |
832 | 842 | return factory |
833 | 843 | 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] |
835 | 847 |
|
836 | 848 |
|
837 | 849 | def _create_scoped_runner_fixture(scope: _ScopeName) -> Callable: |
|
0 commit comments