Pytest----如何使用parametrize参数化对测试数据全排列组合测试

DevOps技术社区 2022-08-29 13:54:12

目录

  • 一、使用parametrize参数化对测试数据全排列组合测试

一、使用parametrize参数化对测试数据全排列组合测试

有时需要对所有数据进行排列组合测试,比如x,y,两个测试数据,期望x和y充分的组合测试,如下

test_demo.py代码如下:

import pytest


@pytest.mark.parametrize("x", [0, 1])
@pytest.mark.parametrize("y", [2, 3])
def test_foo(x, y):
    assert x<y

执行结果如下:

$ pytest -v
========================================================================= test session starts ==========================================================================
platform win32 -- Python 3.9.7, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- D:\Python39\python.exe
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('D:\\src\\blog\\tests\\.hypothesis\\examples')
rootdir: D:\src\blog\tests, configfile: pytest.ini
plugins: allure-pytest-2.9.43, caterpillar-pytest-0.0.2, hypothesis-6.31.6, forked-1.3.0, rerunfailures-10.1, xdist-2.3.0
collected 4 items                                                                                                                                                       

test_demo.py::test_foo[2-0] PASSED                                                                                                                                [ 25%]
test_demo.py::test_foo[2-1] PASSED                                                                                                                                [ 50%]
test_demo.py::test_foo[3-0] PASSED                                                                                                                                [ 75%]
test_demo.py::test_foo[3-1] PASSED                                                                                                                                [100%]

========================================================================== 4 passed in 0.13s ===========================================================================
...全文
115 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

32

社区成员

发帖
与我相关
我的任务
社区描述
围绕测试开发、Devops、软件工程等方向,学习交流,共享技术新动态、新方向。求助工作中的问题,困惑等,互相交流,共同成长
软件工程测试工具devops 技术论坛(原bbs) 江苏省·南京市
社区管理员
  • redrose2100
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

1、社区话题和文章主要围绕DevOps技术栈

2、有广告需求请联系微信 Redrose2100

 

试试用AI创作助手写篇文章吧