Open
Description
When I have the following situation:
- A fixture
main
that uses another fixtureparam
- A test class
TestFoo
that:- overrides the
main
fixture with a fixture that uses the "parent" fixture - has a test
test_foo
that uses themain
fixture and is marked to be parametrised overparam
- overrides the
pytest gives me the error "Failed: In test_foo: function uses no argument 'param'".
I was expecting the "parent" main
fixture to receive the parametrised param
value.
The code:
from pytest import fixture, mark
@fixture
def param() -> int:
return 1
@fixture
def main(param: int) -> int:
return sum(range(param + 1))
class TestFoo:
@fixture
def main(self, main: int) -> int:
return main
@mark.parametrize("param", [2])
def test_foo(self, main: int) -> None:
assert main == 3
The error:
$ pytest
======================================== test session starts =========================================
platform linux -- Python 3.12.2, pytest-8.0.2, pluggy-1.4.0
rootdir: /home/rob/tmp/py
collected 0 items / 1 error
=============================================== ERRORS ===============================================
___________________________________ ERROR collecting test_class.py ___________________________________
In test_foo: function uses no argument 'param'
====================================== short test summary info =======================================
ERROR test_class.py::TestFoo - Failed: In test_foo: function uses no argument 'param'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
========================================== 1 error in 0.05s ==========================================
pip list
output:
$ uv pip list
Package Version
--------- -------
iniconfig 2.0.0
packaging 23.2
pluggy 1.4.0
pytest 8.0.2
OS: Fedora 39.