In pytest 9.1.0, using @pytest.mark.parametrize(..., indirect=True) does not seem to override parameters of a fixture that has parameters explicitly set (i.e., @pytest.fixture(params=[...])) - attempting to do so now results in duplicate parametrization of {fixture_name} error.
This worked with previous releases. git bisect points to d56b1af (and reverting it restores the old behavior).
Minimal example (modeled after pyi_builder fixture from PyInstaller, see here and here):
# test_myfixture.py
import pytest
class MyFixture:
def __init__(self, mode):
self.mode = mode
def do_something(self):
# Do something depending on self.mode
pass
@pytest.fixture(params=['first_mode', 'second_mode'])
def myfixture(request):
yield MyFixture(request.param)
# [1]: typically, both modes are tested
def test_myfixture_default(myfixture):
assert isinstance(myfixture, MyFixture)
assert myfixture.mode in {'first_mode', 'second_mode'}
myfixture.do_something()
# [2]: sometimes, a specific mode is forced
@pytest.mark.parametrize('myfixture', ['first_mode'], indirect=True)
def test_myfixture_single_mode1(myfixture):
assert isinstance(myfixture, MyFixture)
assert myfixture.mode == 'first_mode'
myfixture.do_something()
@pytest.mark.parametrize('myfixture', ['second_mode'], indirect=True)
def test_myfixture_single_mode2(myfixture):
assert isinstance(myfixture, MyFixture)
assert myfixture.mode == 'second_mode'
myfixture.do_something()
Running with 9.0.3:
$ pytest -v -rsfE test_myfixture.py
================================================================================== test session starts ===================================================================================
platform linux -- Python 3.14.5, pytest-9.0.3, pluggy-1.6.0 -- /home/rok/tmp/pyi-pytest/venv/bin/python
cachedir: .pytest_cache
rootdir: /home/rok/tmp/pyi-pytest/myfixture
collected 4 items
test_myfixture.py::test_myfixture_default[first_mode] PASSED [ 25%]
test_myfixture.py::test_myfixture_default[second_mode] PASSED [ 50%]
test_myfixture.py::test_myfixture_single_mode1[first_mode] PASSED [ 75%]
test_myfixture.py::test_myfixture_single_mode2[second_mode] PASSED [100%]
=================================================================================== 4 passed in 0.01s ====================================================================================
Running with pytest 9.1.0:
$ pytest -v -rsfE test_myfixture.py
================================================================================== test session starts ===================================================================================
platform linux -- Python 3.14.5, pytest-9.1.0, pluggy-1.6.0 -- /home/rok/tmp/pyi-pytest/venv/bin/python
cachedir: .pytest_cache
rootdir: /home/rok/tmp/pyi-pytest/myfixture
collected 0 items / 1 error
========================================================================================= ERRORS =========================================================================================
___________________________________________________________________________ ERROR collecting test_myfixture.py ___________________________________________________________________________
test_myfixture.py::test_myfixture_single_mode1: duplicate parametrization of 'myfixture'
================================================================================ short test summary info =================================================================================
ERROR test_myfixture.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
==================================================================================== 1 error in 0.05s ====================================================================================
Since I cannot seem to find any mention of the behavior change in the changelog, I would like to check if the change is intended or not, before making any changes on our end...
In
pytest 9.1.0, using@pytest.mark.parametrize(..., indirect=True)does not seem to override parameters of a fixture that has parameters explicitly set (i.e.,@pytest.fixture(params=[...])) - attempting to do so now results induplicate parametrization of {fixture_name}error.This worked with previous releases.
git bisectpoints to d56b1af (and reverting it restores the old behavior).Minimal example (modeled after
pyi_builderfixture from PyInstaller, see here and here):Running with 9.0.3:
Running with pytest 9.1.0:
Since I cannot seem to find any mention of the behavior change in the changelog, I would like to check if the change is intended or not, before making any changes on our end...