zoukankan      html  css  js  c++  java
  • Pytest中参数化详解

    Pytest中参数化详解1

    '''
        import pytest
    
        def add(a, b):
            return a + b
    
        """参数为列表和元组书写方式一样"""
        # @pytest.mark.parametrize(
            # 'a,b,expect',
            # [
            #     [1,2,3],
            #     [3,4,7],
            #     [7,8,15],
            # ]
            # [
            #     (1, 2, 3),
            #     (3, 4, 7),
            #     (7, 8, 15),
            # ]
        # )
        # def test_add(a, b, expect):
        #     assert add(a, b)==expect
    
        """参数为字典的书写方式"""
        @pytest.mark.parametrize(
            'data',
            [
                {'a':1,'b':2,'expect':3},
                {'a':2,'b':3,'expect':5},
                {'a':3,'b':4,'expect':7},
            ]
        )
        def test_add_01(data):
            assert add(data['a'], data['b'])==data['expect']
    
        if __name__ == '__main__':
            pytest.main(['-s', '-v', 'Pytest中参数化详解(一).py'])
    '''

    Pytest中参数化详解2

    '''
        import pytest
    
        def add(a, b):
            return a + b
    
        @pytest.mark.parametrize(
            'a,b,excepts',
            [
                pytest.param(1, 1, 2, id='1'), # id标识如果用中文,无法解码,最好是用英文及数字表示
                pytest.param(2, 2, 4, id='2'),
                pytest.param(3, 3, 6, id='3'),
            ]
        )
        def test_add(a, b, excepts):
            assert add(a, b)==excepts
    
        if __name__ == '__main__':
            pytest.main(['-v', '-s', 'Pytest中参数化详解(二).py'])
    '''
    while True: print('studying...')
  • 相关阅读:
    jq判断input 复选框有没有选
    jq根据id替换修改或添加css属性
    cookie和session的关系和区别
    tp5 统一返回json格式
    tp5 上传图片(自定义图片路径)
    tp5 生成随机数
    tp5 删除图片以及文件
    tp5 上传视频方法
    tp5 跨域问题
    js替换div里的内容
  • 原文地址:https://www.cnblogs.com/xuewei95/p/15129737.html
Copyright © 2011-2022 走看看