Open
Description
Issue
params
on fixtures that are used by a shadowed but used other fixture are not always detected during test generation and subsequent test execution fails with an error.
Example
@pytest.fixture(params=(1,))
def b(): pass
@pytest.fixture(name="a")
def a1(b): pass
@pytest.fixture(name="a")
def a2(a): pass
def test_deep_params(a): pass
> pytest -q -vvv
============================= test session starts =============================
platform win32 -- Python 3.11.2, pytest-7.4.0, pluggy-1.2.0 -- xxx
cachedir: .pytest_cache
rootdir: xxx
collecting ...
collected 1 item
::test_deep_params ERROR
=================================== ERRORS ====================================
_____________________ ERROR at setup of test_deep_params ______________________
The requested fixture has no parameter defined for test:
::test_deep_params
Requested fixture 'c' defined in:
:24
Requested here:
.venv\Lib\site-packages\_pytest\fixtures.py:712
=========================== short test summary info ===========================
ERROR test_base.py::test_deep_params - Failed: The requested fixture has no p...
============================== 1 error in 0.07s ===============================
Cause
During calculation of the fixture closue only the the arguments of the last FixtureDef
for a fiven argument are expanded.
The sequences of FixtureDef
s are ordered alphabetical by their name (qualname?) of their function object (e.g. swapping the names of a1
and a2
works).
In the example above this result in the arguments of a1
being ignored and b
never being picked up on, resulting in the error at execution time.