我试图在一次测试中多次使用参数化夹具,目的是获得其所有值的笛卡尔积。
https://stackoverflow.com/a/39444098/102441展示了如何为简单的夹具做到这一点:
import pytest
@pytest.fixture(params=[0, 1, 2])
def first(request):
return request.param
second = first
# runs 3x3 = 9 times
def test_double_fixture(first, second):
assert False, '{} {}'.format(first, second)
但是,如果参数化来自依赖夹具,则此方法会崩溃:
import pytest
@pytest.fixture(params=[0, 1, 2])
def integer(request):
return request.param
@pytest.fixture
def squared_integer(integer):
return integer * integer
@pytest.fixture
def first(squared_integer):
return squared_integer
second = first
# runs only 3 times
def test_double_fixture(first, second):
assert False, '{} {}'.format(first, second)
我怎么能像简单的例子那样运行3x3测试呢?