python学习笔记(断言assert)

最近有了些时间

博主一直在python的unittest框架,这次想看看其他框架 

先准备熟悉熟悉 pytest,由于unittest有自己断言方法 而pytest则是使用python自带的 assert

然后博主在这里整理常用的断言情况

 1 # coding=utf-8
 2 
 3 import pytest
 4 
 5 
 6 # 定义待测方法2
 7 def add(a, b):
 8     return a + b
 9 
10 
11 # 定义待测方法2
12 def isNot(a, b, c):
13     if a + b == c:
14         return True
15     else:
16         return False
17 
18 
19 class TestCase:
20     # 相等
21     def test_1(self):
22         assert add(2, 3) == 5
23 
24     # 不等
25     def test_2(self):
26         assert add(2, 3) != 6
27 
28     # 大于
29     def test_3(self):
30         assert add(2, 3) > 4
31 
32     # 小于
33     def test_4(self):
34         assert add(2, 3) < 7
35 
36     # 大于等于
37     def test_5(self):
38         assert add(2, 3) >= 5
39 
40     # 小于等于
41     def test_6(self):
42         assert add(2, 3) <= 5
43 
44     # 包含
45     def test_7(self):
46         assert add(2, 3) in (5, 6, 7)
47 
48     # 不包含
49     def test_8(self):
50         assert add(2, 3) not in (4, 6, 7)
51 
52     # 判断True
53     def test_9(self):
54         assert isNot(2, 3, 5)
55 
56     # 判断False
57     def test_10(self):
58         assert not isNot(2, 3, 6)
59 
60 
61 if __name__ == '__main__':
62     pytest.main()

  

posted on 2018-03-07 10:09  堕落的伊丝莉  阅读(1620)  评论(1编辑  收藏  举报