zoukankan      html  css  js  c++  java
  • 模块四 参数化用例

    pytest数据参数化

    参数化使用

     使用string

    import  pytest
    
    @pytest.mark.parametrize("a,b",[
        (1,2),
        (10,20),
        (100,200)
    ])
    
    class TestDemo:
        def test_param(self,a,b):
            print(a+b)

    使用list

    import  pytest
    
    @pytest.mark.parametrize(['a','b'],[
        (1,2),
        (10,20),
        (100,200)
    ])
    
    class TestDemo:
        def test_param(self,a,b):
            print(a+b)

    使用touple

    import  pytest
    
    @pytest.mark.parametrize(('a','b'),[
        (1,2),
        (10,20),
        (100,200)
    ])
    
    class TestDemo:
        def test_param(self,a,b):
            print(a+b)

    yaml参数

    yaml实现list

    yaml实现字典

    yaml进行嵌套

    加载yaml文件

    import  pytest
    import yaml
    
    
    @pytest.mark.parametrize("a,b",yaml.safe_load(open("./date.yaml")))
    
    class TestDemo:
        def test_param(self,a,b):
            print(a+b)
  • 相关阅读:
    【Coreforces 1253E】
    计数专题乱做
    PKUWC2020乱做
    多项式板子
    notepad
    2021.4.9
    2021.4.8
    2021.3.31
    2021.3.26
    2021.3.25
  • 原文地址:https://www.cnblogs.com/hantongxue/p/14327037.html
Copyright © 2011-2022 走看看