Skip to content

Commit b194dae

Browse files
committed
fix: Do not try to initialize async fixtures without explicit asyncio mark in strict mode.
This fixes a bug that breaks compatibility with pytest_trio. Closes pytest-dev#298 Signed-off-by: Michael Seifert <[email protected]>
1 parent e0faa98 commit b194dae

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

CHANGELOG.rst

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Changelog
55
UNRELEASED
66
=================
77
- Adds `pytest-trio <https://pypi.org/project/pytest-trio/>`_ to the test dependencies
8+
- Fixes a bug that caused pytest-asyncio to try to set up async pytest_trio fixtures in strict mode. `#298 <https://github.com/pytest-dev/pytest-asyncio/issues/298>`_
89

910
0.18.2 (22-03-03)
1011
=================

pytest_asyncio/plugin.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,11 @@ def _preprocess_async_fixtures(config: Config, holder: Set[FixtureDef]) -> None:
210210
# Nothing to do with a regular fixture function
211211
continue
212212
if not _has_explicit_asyncio_mark(func):
213-
if asyncio_mode == Mode.AUTO:
213+
if asyncio_mode == Mode.STRICT:
214+
# Ignore async fixtures without explicit asyncio mark in strict mode
215+
# This applies to pytest_trio fixtures, for example
216+
continue
217+
elif asyncio_mode == Mode.AUTO:
214218
# Enforce asyncio mode if 'auto'
215219
_set_explicit_asyncio_mark(func)
216220
elif asyncio_mode == Mode.LEGACY:

tests/trio/test_fixtures.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from textwrap import dedent
2+
3+
4+
def test_strict_mode_ignores_trio_fixtures(testdir):
5+
testdir.makepyfile(
6+
dedent(
7+
"""\
8+
import pytest
9+
import pytest_asyncio
10+
import pytest_trio
11+
12+
pytest_plugins = ["pytest_asyncio", "pytest_trio"]
13+
14+
@pytest_trio.trio_fixture
15+
async def any_fixture():
16+
return True
17+
18+
@pytest.mark.trio
19+
async def test_anything(any_fixture):
20+
pass
21+
"""
22+
)
23+
)
24+
result = testdir.runpytest("--asyncio-mode=strict")
25+
result.assert_outcomes(passed=1)

0 commit comments

Comments
 (0)