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为变量)
结果输出:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)