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

相关推荐
西游音月3 小时前
(4)pytest+Selenium自动化测试-元素定位之CSS Selector定位
css·selenium·pytest
淼_@淼2 天前
pytest-数据驱动
pytest
我的xiaodoujiao2 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 27--二次封装方法--优化断言结果
python·学习·测试工具·pytest
淼_@淼4 天前
pytest简介
运维·服务器·pytest
奶茶精Gaaa5 天前
【ZJ】Pytest框架搭建
pytest
趙卋傑5 天前
接口自动化测试
python·pycharm·pytest
测试界萧萧7 天前
Jenkins+Allure+Pytest的持续集成
自动化测试·软件测试·功能测试·程序人生·ci/cd·jenkins·pytest
nvd118 天前
Pytest 中使用 SQLAlchemy 进行异步数据库测试
数据库·oracle·pytest
文人sec9 天前
pytest1-接口自动化测试场景
软件测试·python·单元测试·pytest
我的xiaodoujiao9 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 25--数据驱动--参数化处理 Excel 文件 2
前端·python·学习·测试工具·ui·pytest