1 #功能函数
2 def multiply(a,b):
3 return a * b
4
5 # ==========fixture==========
6 def setup_module(): #模块级:在当前文件中,在所有测试用例执行之前与之后执行
7 print("setup_module==========")
8
9 def teardown_module():
10 print("teardown_module===========")
11
12 def setup_function(): #函数级:在每个测试函数之前与之后执行(不在类中)
13 print("setup_function---------------")
14
15 def teardown_function():
16 print("teardown_function---")
17
18 def setup(): #类里面:运行在调用方法的前后(类里面)
19 print("setup......")
20
21 def teardown():
22 print("teardown...")
23
24 #测试用例
25 def test_multipy_3():
26 print("test_multiply_3....")
27 assert multiply(3,4) == 12
28
29 def test_multiply_4():
30 print("test_multiply_4")
31 assert multiply('a',3) == 'aaa'
1 def multiply(a,b):
2 return a*b
3
4 class TestMultipy:
5 #========fixture======
6 @classmethod
7 def setup_class(self): #类级:只在类中当前后运行一次(在类中)
8 print("setup_class==============")
9
10 @classmethod
11 def teardown_class(cls):
12 print("teardown_class=====")
13
14 def setup_method(self): #方法级:在每个测试方法开始于结束时执行(在类中)
15 print("setup_method--------")
16
17 def teardown_class(self):
18 print("teardown_class--")
19
20 def setup(self):
21 print("setup.......")
22
23 def teardown(self):
24 print("teardown...")
25
26
27 #========测试用例======
28 def test_numbers_5(self):
29 print("test_numbers_5")
30 assert multiply(5,6) == 30
31
32 def test_numbers_6(self):
33 print("test_numbers_6")
34 assert multiply('b',2) == 'bb'