diff --git a/README.rst b/README.rst index e1e432f2..0c87bfbc 100644 --- a/README.rst +++ b/README.rst @@ -257,6 +257,10 @@ or an async framework such as `asynctest `_ + 0.18.0 (22-02-07) ~~~~~~~~~~~~~~~~~~~ diff --git a/pytest_asyncio/plugin.py b/pytest_asyncio/plugin.py index f0374893..1ecfbe49 100644 --- a/pytest_asyncio/plugin.py +++ b/pytest_asyncio/plugin.py @@ -319,12 +319,12 @@ def pytest_pycollect_makeitem( """A pytest hook to collect asyncio coroutines.""" if not collector.funcnamefilter(name): return None + _preprocess_async_fixtures(collector.config, _HOLDER) if ( _is_coroutine(obj) or _is_hypothesis_test(obj) and _hypothesis_test_wraps_coroutine(obj) ): - _preprocess_async_fixtures(collector.config, _HOLDER) item = pytest.Function.from_parent(collector, name=name) marker = item.get_closest_marker("asyncio") if marker is not None: diff --git a/tests/test_asyncio_fixture.py b/tests/test_asyncio_fixture.py index cfe10479..3a28cebb 100644 --- a/tests/test_asyncio_fixture.py +++ b/tests/test_asyncio_fixture.py @@ -1,4 +1,5 @@ import asyncio +from textwrap import dedent import pytest @@ -39,3 +40,25 @@ async def fixture_with_params(request): async def test_fixture_with_params(fixture_with_params): await asyncio.sleep(0) assert fixture_with_params % 2 == 0 + + +@pytest.mark.parametrize("mode", ("auto", "strict", "legacy")) +def test_sync_function_uses_async_fixture(testdir, mode): + testdir.makepyfile( + dedent( + """\ + import pytest_asyncio + + pytest_plugins = 'pytest_asyncio' + + @pytest_asyncio.fixture + async def always_true(): + return True + + def test_sync_function_uses_async_fixture(always_true): + assert always_true is True + """ + ) + ) + result = testdir.runpytest(f"--asyncio-mode={mode}") + result.assert_outcomes(passed=1)