在pytest中使用参数化,方式如下:
import pytest
testparams = [
(1, 2, 3, 4, 5, 6, 7),
(7, 6, 5, 4, 3, 2, 1),
]
@pytest.mark.parametrize('a, b, c, d, e, f, g', testparams)
def test_many_args(a, b, c, d, e, f, g):
assert d == 4
可以发现 在pytest.mark.parametrize
写了参数名a,b,c,d,e,f,g, 在test_many_args中又写了a,b,c,d,e,f,g一遍,重复编写了参数,有什么方法可以去除呢?
经过探索,现已完成去除重复编写参数的功能。
import pytest
testparams = [
(1, 2, 3, 4, 5, 6, 7),
(7, 6, 5, 4, 3, 2, 1),
]
@pytest.auto_parametrize(testparams)
def test_many_args(a, b, c, d, e, f, g):
assert d == 4