I have two parameterized fixtures that are similar (fixture A and B). In addition to this, fixture B needs some additional information from another fixture (fixture C). I don't always want to create the object returned by fixture C, and that's why I want to keep A and B separated in the first place.
I also have a fourth fixture (D), which I want to run with either A or B, depending on the scenario.
I am able to run D with either A or B by using pytest-lazy-fixtures, but I am not able to parameterize them. I have also tried to use request.getfixturevalue and looked at pytest-cases, but still not able to parameterize A or B. Is there any (elegant) way to do it? I am open to try other packages and design patterns - no special requirement to use lazy_fixture.
The code is similar to this:
import pytest
from pytest_lazyfixture import lazy_fixture
@pytest.fixture()
fixture_c():
...
@pytest.fixture()
fixture_a(request):
param1 = request.param["param1"]
param2 = request.param["param2"]
...
@pytest.fixture()
fixture_b(fixture_c, request):
param1 = request.param["param1"]
param2 = request.param["param2"]
...
@pytest.fixture()
fixture_d(request):
initial_fixture = request.param["initial_fixture"]
...
@pytest.mark.parametrize(
"fixture_b, fixture_d",
[
pytest.param(
{
"param1": "abcd"
"param2": "123"
},
{
"initial_fixture": lazy_fixture("fixture_b")
}
)
],
indirect=True,
)
def test_parameterize_fixtures(fixture_d):
...