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

相关推荐
唐古乌梁海11 小时前
【pytest 】 pytest 生命周期
pytest
专职2 天前
pytest详细教程
开发语言·python·pytest
乄捷径2 天前
pytest入门到熟练
pytest
专职2 天前
pytest+requests+allure生成接口自动化测试报告
开发语言·python·pytest
小熊出擊3 天前
【pytest】fixture 内省(Introspection)测试上下文
python·单元测试·pytest
小熊出擊4 天前
【pytest】finalizer 执行顺序:FILO 原则
python·测试工具·单元测试·pytest
小熊出擊5 天前
【pytest】使用 marker 向 fixture 传递数据
python·pytest
wa的一声哭了5 天前
Deep Learning Optimizer | Adam、AdamW
人工智能·深度学习·神经网络·机器学习·自然语言处理·transformer·pytest
专职7 天前
pytest生成测试用例,allure生成测试报告
测试用例·pytest
小丁爱养花10 天前
接口自动化测试 - pytest [1]
python·自动化·pytest