1.单参数,多参数
# 单参数
@pytest.mark.parametrize("expression",["1+1","2-1","2*3","4/2"])
def test_calc(expression):
ret=calc(expression)
assert 1==ret
# 多参数
@pytest.mark.parametrize("expression,expect_value",[
("1+1",2),
("1-1",0),
("1*3",3),
("3/3",1)
])
def test_calcs(expression,expect_value):
ret=calc(expression)
assert expect_value==ret
if __name__ == '__main__':
pytest.main([__file__,"-s"])
2.参数组合
# 参数组合
@pytest.mark.parametrize("a,c",[(1,2),(2,1),(3,5),(4,2)])
@pytest.mark.parametrize("b",["+","-","*","/"])
def test_compose(a,b,c):
express="{}{}{}".format(a,b,c)
ret=calc(express)
if b=="+":
assert ret==a+c
if b=="-":
assert ret==a-c
if b=="*":
assert ret==a*c
if b=="/":
assert ret==a/c
@pytest.mark.parametrize("p1",["m1","m2"])
@pytest.mark.parametrize("p2",["f1","f2","f3"])
def test_xiangqing(p1,p2):
print("%s_%s"%(p1,p2))