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

相关推荐
Tom Boom1 天前
Pytest断言全解析:掌握测试验证的核心艺术
自动化测试·python·测试开发·pytest
不要一直敲门3 天前
初学 pytest 记录
pytest
测试界清流3 天前
Selenium4+Pytest自动化测试框架
selenium·测试工具·pytest
努力搬砖的咸鱼5 天前
从零开始搭建 Pytest 测试框架(Python 3.8 + PyCharm 版)
python·pycharm·pytest
FINE!(正在努力!)7 天前
PyTest框架学习
学习·pytest
程序员杰哥8 天前
接口自动化测试之pytest 运行方式及前置后置封装
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest
测试老哥8 天前
Pytest+Selenium UI自动化测试实战实例
自动化测试·软件测试·python·selenium·测试工具·ui·pytest
水银嘻嘻8 天前
07 APP 自动化- appium+pytest+allure框架封装
python·appium·自动化·pytest
天才测试猿9 天前
接口自动化测试之pytest接口关联框架封装
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·pytest
not coder10 天前
Pytest Fixture 详解
数据库·pytest