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

相关推荐
测试老哥10 小时前
pytest+requests+allure自动化测试接入Jenkins学习
自动化测试·软件测试·学习·测试工具·职场和发展·jenkins·pytest
丿罗小黑12 小时前
Pytest项目_day20(log日志)
pytest
xt198928812 小时前
pytest+yaml+allure接口自动化测试框架
自动化测试·pytest·接口自动化·框架封装
灰阳阳12 小时前
接口自动化测试大全(python+pytest+allure)
python·pytest·接口自动化·allure
5:003 天前
pytest框架-详解
pytest
丿罗小黑5 天前
Pytest项目_day15(yaml)
pytest
丿罗小黑5 天前
Pytest项目_day16(yaml和parametrize结合)
pytest
代码小念6 天前
Pytest+selenium UI自动化测试实战实例(超详细)
selenium·ui·pytest
丿罗小黑7 天前
Pytest项目_day11(fixture、conftest)
pytest