码迷,mamicode.com
首页 > 其他好文 > 详细

pytest学习系列_参数化详解

时间:2020-12-02 12:33:04      阅读:4      评论:0      收藏:0      [点我收藏+]

标签:赋值   rgb   assert   param   元组   exp   步骤   __name__   turn   

本质:测试步骤一致,测试数据不同

import pytest

‘‘‘
是对列表中的对象循环,然后一一的赋值
对象:
列表
元组
字典
‘‘‘
def add(a,b): return a + b #列表 @pytest.mark.parametrize(‘a,b,expect‘,[ [1,1,2], [2,2,4], [3,3,6], [4,4,8] ]) def test_add(a,b,expect): assert add(a,b) == expect #元组 @pytest.mark.parametrize(‘a,b,expect‘,[ (1,1,2), (2,2,4), (3,3,6), (4,4,8) ]) def test_add(a,b,expect): assert add(a,b) == expect #字典 @pytest.mark.parametrize(‘data‘,[ {‘a‘:1,‘b‘:1,‘expect‘:2}, {‘a‘:4,‘b‘:4,‘expect‘:8} ]) def test_add(data): assert add(data[‘a‘],data[‘b‘]) == data[‘expect‘] @pytest.mark.parametrize(‘a,b,expect‘,[ pytest.param(1, 1, 2, id=‘one‘), pytest.param(2, 2, 4, id=‘two‘), pytest.param(3, 3, 6, id=‘three‘), pytest.param(4, 4, 8, id=‘four‘) ]) def test_add(a,b,expect): assert add(a,b) == expect if __name__ == ‘__main__‘: pytest.main(["-s","-v","test_parametrize.py"])

pytest学习系列_参数化详解

标签:赋值   rgb   assert   param   元组   exp   步骤   __name__   turn   

原文地址:https://www.cnblogs.com/Durant0420/p/14051118.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!