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的执行。

相关推荐
念越17 小时前
Allure 测试报告保姆级教程:从安装到 pytest 集成与报告生成
pytest·allure
念越1 天前
接口自动化测试从入门到实战:接口用例设计、Requests、Pytest、YAML、JSON Schema 与 Allure 报告
python·测试工具·自动化·json·pytest
霍格沃兹测试学院-小舟畅学5 天前
AI+Swagger:一键生成500条pytest接口用例
人工智能·pytest
把头塞进显示器14 天前
电商平台-测试报告
python·selenium·pytest
昔我往昔19 天前
pytest日志问题排查记录
python·pytest
黄昏恋慕黎明22 天前
博客论坛技术迭代
python·pytest
2601_9620782322 天前
Python接口自动化流程(pytest)
python·pytest·接口自动化·测试框架·断言
杨女士YRJ22 天前
python+pytest+01
python·pytest
2601_9620782323 天前
Python接口自动化框架:pytest
python·pytest·接口自动化·测试框架·restfulapi
2601_9620781923 天前
Appium+Python+pytest自动化测试框架详解
自动化测试·python·appium·pytest·移动应用