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为变量)

结果输出:

posted @   鱼的记忆·  阅读(132)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示