Skip to content

Commit

Permalink
fix: Do not try to initialize async fixtures without explicit asyncio…
Browse files Browse the repository at this point in the history
… mark in strict mode.

This fixes a bug that breaks compatibility with pytest_trio.

Closes pytest-dev#298

Signed-off-by: Michael Seifert <m.seifert@digitalernachschub.de>
  • Loading branch information
seifertm committed Mar 11, 2022
1 parent e0faa98 commit b194dae
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Changelog
UNRELEASED
=================
- Adds `pytest-trio <https://pypi.org/project/pytest-trio/>`_ to the test dependencies
- 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>`_

0.18.2 (22-03-03)
=================
Expand Down
6 changes: 5 additions & 1 deletion pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ def _preprocess_async_fixtures(config: Config, holder: Set[FixtureDef]) -> None:
# Nothing to do with a regular fixture function
continue
if not _has_explicit_asyncio_mark(func):
if asyncio_mode == Mode.AUTO:
if asyncio_mode == Mode.STRICT:
# Ignore async fixtures without explicit asyncio mark in strict mode
# This applies to pytest_trio fixtures, for example
continue
elif asyncio_mode == Mode.AUTO:
# Enforce asyncio mode if 'auto'
_set_explicit_asyncio_mark(func)
elif asyncio_mode == Mode.LEGACY:
Expand Down
25 changes: 25 additions & 0 deletions tests/trio/test_fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from textwrap import dedent


def test_strict_mode_ignores_trio_fixtures(testdir):
testdir.makepyfile(
dedent(
"""\
import pytest
import pytest_asyncio
import pytest_trio
pytest_plugins = ["pytest_asyncio", "pytest_trio"]
@pytest_trio.trio_fixture
async def any_fixture():
return True
@pytest.mark.trio
async def test_anything(any_fixture):
pass
"""
)
)
result = testdir.runpytest("--asyncio-mode=strict")
result.assert_outcomes(passed=1)

0 comments on commit b194dae

Please sign in to comment.