其他分享
首页 > 其他分享> > pytest的参数化计算--@pytest.mark.parametrize

pytest的参数化计算--@pytest.mark.parametrize

作者:互联网

class  Test_ClareTestClass():
def setup_class(self):
self.executor = ClareTestClass(1,5)

#这样的参数化,是总共执行了3次,pytest的统计结果算3个测试用例
@pytest.mark.parametrize("arg1,arg2,result",[(1,2,3),(2,3,5),(3,4,7)])
def test_add(self,arg1,arg2,result):
res= arg1+arg2
assert res == result

#这样的参数化,是总共执行了7*7*7 ,343次,pytest统计为343个测试用例,就是三个参数分别相乘的结果
@pytest.mark.parametrize("arg1",[1,2,3,4,5,6,7])
@pytest.mark.parametrize("arg2",[1,2,3,4,5,6,7])
@pytest.mark.parametrize("result",[2,4,6,8,10,12,14])
def test_sub(self,arg1,arg2,result):
res=arg1+arg2
assert res==result

标签:parametrize,--,arg1,arg2,mark,pytest,result
来源: https://www.cnblogs.com/renjie1105/p/15477074.html