标签:赋值 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"])
标签:赋值 rgb assert param 元组 exp 步骤 __name__ turn
原文地址:https://www.cnblogs.com/Durant0420/p/14051118.html