- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.9k
Closed
Labels
topic: fixturesanything involving fixtures directly or indirectlyanything involving fixtures directly or indirectlytopic: parametrizerelated to @pytest.mark.parametrizerelated to @pytest.mark.parametrizetype: bugproblem that needs to be addressedproblem that needs to be addressed
Description
When I have the following situation:
- A fixture mainthat uses another fixtureparam
- A test class TestFoothat:- overrides the mainfixture with a fixture that uses the "parent" fixture
- has a test test_foothat uses themainfixture 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 == 3The 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.
Metadata
Metadata
Assignees
Labels
topic: fixturesanything involving fixtures directly or indirectlyanything involving fixtures directly or indirectlytopic: parametrizerelated to @pytest.mark.parametrizerelated to @pytest.mark.parametrizetype: bugproblem that needs to be addressedproblem that needs to be addressed