22、pytest多个参数化的组合

官方实例

python 复制代码
# content of test_multi_parametrie.py
import pytest

@pytest.mark.parametrize("x",[0,1])
@pytest.mark.parametrize("y",[2,3])
def test_foo(x,y):
    print("{}-{}".format(x,y))
    pass

解读与实操

要获得多个参数化参数的所有组合,你可以堆叠参数化装饰器。

这将运行测试,将参数设置为x=0/y=2,x=1/y=2,x=0/y=3和x=1/y=3,按照装饰器的顺序耗尽参数。

场景应用

由pytest自由构造多组参数的笛卡尔积组合时,可以使用这种方式。但使用时要注意避免参数爆炸,太多或穷尽的参数可以会减慢pytest的执行。

相关推荐
思则变2 天前
[Pytest][Part 1]Pytest 自动化测试框架
pytest
思则变3 天前
[Pytest] [Part 2]增加 log功能
开发语言·python·pytest
思则变4 天前
[Pytest][Part 3]检测python package状态
pytest
cooldream200918 天前
pytest 框架详解与实战指南
pytest·测试
慕城南风18 天前
【pytest进阶】Pytest之conftest详解
pytest
编程小白gogogo19 天前
AI自动化测试速成(Pytest框架)
pytest
慕城南风19 天前
【pytest进阶】pytest详解及进阶使用
linux·服务器·pytest
Tom Boom1 个月前
Pytest断言全解析:掌握测试验证的核心艺术
自动化测试·python·测试开发·pytest
不要一直敲门1 个月前
初学 pytest 记录
pytest