Python Fixture——通常用来对测试方法、测试函数、测试类和整个测试文件进行初始化或还原测试环境
2021/9/11 20:06:49
本文主要是介绍Python Fixture——通常用来对测试方法、测试函数、测试类和整个测试文件进行初始化或还原测试环境,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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'
这篇关于Python Fixture——通常用来对测试方法、测试函数、测试类和整个测试文件进行初始化或还原测试环境的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python