1.单参数,多参数

    1. # 单参数
    2. @pytest.mark.parametrize("expression",["1+1","2-1","2*3","4/2"])
    3. def test_calc(expression):
    4. ret=calc(expression)
    5. assert 1==ret
    6. # 多参数
    7. @pytest.mark.parametrize("expression,expect_value",[
    8. ("1+1",2),
    9. ("1-1",0),
    10. ("1*3",3),
    11. ("3/3",1)
    12. ])
    13. def test_calcs(expression,expect_value):
    14. ret=calc(expression)
    15. assert expect_value==ret
    16. if __name__ == '__main__':
    17. pytest.main([__file__,"-s"])

    2.参数组合

    1. # 参数组合
    2. @pytest.mark.parametrize("a,c",[(1,2),(2,1),(3,5),(4,2)])
    3. @pytest.mark.parametrize("b",["+","-","*","/"])
    4. def test_compose(a,b,c):
    5. express="{}{}{}".format(a,b,c)
    6. ret=calc(express)
    7. if b=="+":
    8. assert ret==a+c
    9. if b=="-":
    10. assert ret==a-c
    11. if b=="*":
    12. assert ret==a*c
    13. if b=="/":
    14. assert ret==a/c
    15. @pytest.mark.parametrize("p1",["m1","m2"])
    16. @pytest.mark.parametrize("p2",["f1","f2","f3"])
    17. def test_xiangqing(p1,p2):
    18. print("%s_%s"%(p1,p2))