pytest_parametrize indirect间接参数用法
indirect参数
- indirect参数值为True,False
- 间接用于特定参数
参数值为布尔值的先不看,主要记录下indirect 间接用于特定参数,先看官方demo
import pytest
@pytest.fixture(scope='function')
def x(request):
return request.param * 3
@pytest.fixture(scope='function')
def y(request):
return request.param * 2
@pytest.mark.parametrize('x,y', [['a', 'b']], indirect=['x'])
def test_x(x, y):
assert x == 'aaa'
assert y == 'b'
@pytest.mark.parametrize('x,y', [['a', 'b']], indirect=['x','y'])
def test_x_y(x, y):
assert x == 'aaa'
assert y == 'bb'
if __name__ == '__main__':
pytest.main(['-sv', "test_pytest_indirect_demo14_ui.py"])
官方解释:

简单理解:
indirect参数可接受一个列表或元祖,列表或元祖里面的值由对应夹具名称组成,若有此值,则parametrize第一个字符串参数中夹具名为函数,否则为变量值。(列表或元祖有对应夹具值,则会使用fixture函数,没有该fixture为变量)
结果输出:


浙公网安备 33010602011771号