一、环境准备
1.安装ddt模块,打开cmd输入pip install ddt在线安装
二、数据驱动原理
1.测试数据为多个字典的list类型
4.运行后用例会自动加载成三个单独的用例
# coding:utf-8
import ddt
import unittest
# 测试数据
test_data = [{"username": "zhangsan", "pwd": "zhangsan"},
{"username": "lisi", "pwd": "lisi"},
{"username": "wangwu", "pwd": "wangwu"},
]
test_data2 = [{"username": "wukong", "pwd": "wukong"},
{"username": "wuneng", "pwd": "woneng"},
{"username": "wujing", "pwd": "wujing"},
]
@ddt.ddt
class Test(unittest.TestCase):
def setUp(self):
print("Start!")
def tearDown(self):
print("end!")
@ddt.data(*test_data)
def test_ddt1(self, data):
print(data)
@ddt.data(*test_data2)
def test_ddt2(self, data):
print(data)
if __name__ == "__main__":
unittest.main()
原文:http://www.cnblogs.com/lingzeng86/p/6790827.html