32
社区成员




有时需要对所有数据进行排列组合测试,比如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 ===========================================================================