在pytest中使用2个参数进行参数化测试

时间:2019-12-05 08:10:40

标签: python pytest

import pytest


@pytest.mark.parametrize("x", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
@pytest.mark.parametrize("y", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
def test_foo(x, y):
 pass

如何设置“ x”和“ y”的范围,例如x [0-16]和y [0-10]

1 个答案:

答案 0 :(得分:1)

您正在寻找内置的range。下面的示例:

import pytest


@pytest.mark.parametrize("x", range(17))
@pytest.mark.parametrize("y", range(11))
def test_foo(x, y):
 pass

然后,根据您指定的范围(不包括该数字)更改上面的数字(即range(17)为0-16)