This is a common use case which is understand doesn't have a straightforward answer. Here is my usecase:
@pytest.fixture(name="hc_tags", params=[("Label", TR.LabelMixin)])
def _hc_tags(request):
return request.param
@pytest.fixture
def Type_HC_Passive(hc_tags):
...
return PassiveObj
@pytest.fixture
def Type_HC_Active(hc_tags):
...
return ActiveObj
@pytest.mark.parametrize("Type_HCBase_Fx",
[('Type_HC_Passive'),
('Type_HC_Active')
]
)
def test_Type_HCBaseType_HCBase_Fx, request):
Type_HCBase = request.getfixturevalue(Type_HCBase_Fx)
<do-some-test-asserts>
This errors with following message:
The requested fixture has no parameter defined for test:
tests_internal/test_internal.py::test_Type_HCBase[Type_HC_Passive]
Requested fixture 'hc_tags' defined in:
tests_internal/test_internal.py:32
I have an approach using pytest_cases. Unfortunately, it is not compatible with pytest.
and then use
@parametrize_with_cases("Type_HCBase_NoStub", cases='.', prefix='Type_')This isn't be best solution since I cannot decorate Type_HC_Passive using @pytest.fixture which means I have to test_cases for all the tests. test_cases should be separate framework and not part of pytest. It doesn't make sense to put incompatible frameworks together.