Pytest Parametrize

时间:2017-12-19 10:05:22

标签: python pytest


     |  WHERE INTEREST REGEXP '(?=.*0[1])(?=.*0[2])(?=.*0[3])' """) 
 result.show

正如我执行上面的代码所期望的那样,我将获得如下组合:

迭代-1)x = 0,y = 2,迭代-2)x = 1,y = 2,迭代-3)x = 0,y = 3,4)x = 1,y = 3

但有没有办法选择/限制组合或打印如下

iteration-1)x = 0,y = 2,iteration-2)x = 0,y = 3,iteration-3)x = 1,y = 2,4)x = 1,y = 3

由于

2 个答案:

答案 0 :(得分:3)

最简单的解决方案是只使用一个parametrize装饰器

import pytest

@pytest.mark.parametrize("x,y", [(0,2), (0, 3), (1, 2), (1, 3)])
def test_func(x, y):
    pass

答案 1 :(得分:0)

只需更改参数的顺序:

import pytest

@pytest.mark.parametrize("y", [2, 3])
@pytest.mark.parametrize("x", [0, 1])
def test_func(x, y):
    pass

它将给出预期的迭代次数

1)x = 0,y = 2,迭代2)x = 0,y = 3,迭代3)x = 1,y = 2,4)x = 1,y = 3