我有两个简单的测试设置,我试图将它们组合在一个夹具中,并希望测试功能将“参数”传递给夹具。
这是一个人为的例子,来解释我的问题。假设我有以下 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
当然,上述方法是行不通的。实际情况要复杂一些,但我只想知道是否可以将函数传递params=['param1','param2']
给夹具test_madeup
。