数据驱动——ddt
1: pip3 install ddt
2:
@ddt 装饰
@data((2,3),(4,5)) 支持列表,元祖,字典
@unpack 解压数据
1 import unittest
2 from ddt import ddt,data,unpack
3
4 @ddt
5 class MyTesting(unittest.TestCase):
6 @data([3,2,1],[5,3,2],[10,4,6])
7 @unpack
8 def test_01baidu(self,a,b,expected):
9 actual = int(a) - int(b)
10 expected = int(expected)
11 self.assertEqual(actual, expected)
12
13 @data((2,3),(4,5))
14 @unpack
15 def test_02baidu(self,a,b):
16 self.assertEqual(a,b)
17
18 @data({"1":1,"2":2})
19 @unpack
20 def test_03baidu(self, a, b):
21 self.assertEqual(a, b)
22
23
24 if __name__ == '__main__':
25 unittest.main(verbosity=2)