我有两个简单的测试设置,并且我正在尝试将它们分组在一个夹具中,并希望测试函数将“params”传递给夹具。
以下是一个假想的示例,用于解释我的问题。假设我有以下pytest夹具:
@pytest.fixture(scope="module", params=['param1','param2'])
def myFixture(request):
if request.param == 'param1':
p = 5
elif request.param == 'param2':
p = 10
return p
# would like to set request.param = ['param1'] for myFixture
def test_madeup(myFixture):
assert myFixture == 5
# would like to set request.param = ['param2'] for myFixture
def test_madeup2(myFixture):
assert myFixture == 10
我能否将上述参数作为输入传递给test_madeup
函数?像下面这样:
@pytest.fixture(scope="module", params=fixtureParams)
def myFixture(request):
if request.param == 'param1':
return 5
elif request.param == 'param2':
return 10
def test_madeup(myFixture, ['param1']):
assert myFixture == 5
当然,上面的方法是行不通的。实际情况要更加复杂一些,但我只想知道是否可以从test_madeup
函数将params=['param1','param2']
传递给fixture。