From fb81dfe6f64017c589f5171d08485432da058485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20Gr=C3=B6nholm?= Date: Mon, 14 Oct 2024 01:01:35 +0300 Subject: [PATCH] Fixed a regression in the pytest plugin that broke parametrized async fixtures --- docs/versionhistory.rst | 5 +++++ src/anyio/pytest_plugin.py | 2 +- tests/test_pytest_plugin.py | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/versionhistory.rst b/docs/versionhistory.rst index d2db435b..19e6f14b 100644 --- a/docs/versionhistory.rst +++ b/docs/versionhistory.rst @@ -3,6 +3,11 @@ Version history This library adheres to `Semantic Versioning 2.0 `_. +**UNRELEASED** + +- Fixed regression caused by (`#807 `_) + that prevented the use of parametrized async fixtures + **4.6.1** This release contains all the changes from both v4.5.1 and v4.6.0, plus: diff --git a/src/anyio/pytest_plugin.py b/src/anyio/pytest_plugin.py index 0c42ab71..4a0d59dd 100644 --- a/src/anyio/pytest_plugin.py +++ b/src/anyio/pytest_plugin.py @@ -91,7 +91,7 @@ def wrapper( kwargs["anyio_backend"] = anyio_backend if has_request_arg: - kwargs["request"] = anyio_backend + kwargs["request"] = request with get_runner(backend_name, backend_options) as runner: if isasyncgenfunction(local_func): diff --git a/tests/test_pytest_plugin.py b/tests/test_pytest_plugin.py index f1b20f91..ff522544 100644 --- a/tests/test_pytest_plugin.py +++ b/tests/test_pytest_plugin.py @@ -541,3 +541,23 @@ def test_no_mark(fixt): result = testdir.runpytest(*pytest_args) result.assert_outcomes(passed=len(get_all_backends()) + 1) + + +def test_async_fixture_params(testdir: Pytester) -> None: + testdir.makepyfile( + """ + import inspect + import pytest + + @pytest.fixture(params=[1, 2]) + async def fixt(request): + return request.param + + @pytest.mark.anyio + async def test_params(fixt): + assert fixt in (1, 2) + """ + ) + + result = testdir.runpytest(*pytest_args) + result.assert_outcomes(passed=len(get_all_backends()) * 2)