Imagine the following testsuite
import pytest
@pytest.fixture(params=1, 2, 3)
def shape(request):
return request.param
@pytest.fixture
def data(shape):
return shape
def test_resize(data, shape):
pass
where I have two fixtures data and shape. data depends on the fixture shape and is being generated for each of the possible values. But in test_resize I want to test over all possible combinations of data and shape:
- 1, 1
- 1, 2
- 1, 3
- 2, 1
etc. With the implementation above it does not expand the carthesian product though:
- 1, 1
- 2, 2
- 3, 3
Is there a way to make py.test expand the fixtures to all possible combinations?
As your output shows,
shapeis parameterized butdatais not, thus there will only be one instance of thedatafixture for each instance of theshapefixture. I would also parameterizedata. Then, still having thedatafixture depend uponshape, you'll get the product you desire: