神剑山庄资源网 Design By www.hcban.com
pytest的setup与teardown
1)pytest提供了两套互相独立的setup 与 teardown和一对相对自由的setup与teardown
2)模块级与函数级
模块级(setup_module/teardown_module) #开始于模块始末(不在类中)
函数级(setup_function/teardown_function) #只对函数用例生效(不在类中)
3)方法级与类级
方法级(setup_method/teardown_method) #开始于方法始末(在类中)
类级(setup_class/teardown_class) #只在类中前后运行一次(在类中)
3)类里面的(setup/teardown) #运行在调用方法的前后
setup与teardown例子
import pytest # 模块中的方法 def setup_module(): print( "setup_module:整个test_module.py模块只执行一次" ) def teardown_module(): print( "teardown_module:整个test_module.py模块只执行一次" ) def setup_function(): print("setup_function:每个用例开始前都会执行") def teardown_function(): print("teardown_function:每个用例结束后都会执行") # 测试模块中的用例1 def test_one(): print("正在执行测试模块----test_one") # 测试模块中的用例2 def test_two(): print("正在执行测试模块----test_two") # 测试类 class TestCase(): def setup_class(self): print("setup_class:所有用例执行之前") def teardown_class(self): print("teardown_class:所有用例执行之后") def setup_method( self): print("setup_method: 每个用例开始前执行") def teardown_method(self): print("teardown_method: 每个用例结束后执行") def setup(self): print("setup:每个用例开始前都会执行") def teardown(self): print("teardown:每个用例结束后都会执行") def test_three(self): print("正在执行测试类----test_three") def test_four(self): print("正在执行测试类----test_four") if __name__ == "__main__": pytest.main(["-s", "test_module.py"])
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
神剑山庄资源网 Design By www.hcban.com
神剑山庄资源网
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com
暂无简单了解pytest测试框架setup和tearDown的评论...
更新日志
2024年09月30日
2024年09月30日
- 孙悦.1996-伙伴【正大国际】【WAV+CUE】
- 纪钧瀚《钢琴阅读时光 雨中书店聆听轻音乐》[FLAC/分轨][399.62MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[320K/MP3][87.4MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[FLAC/分轨][184.94MB]
- 陈慧娴.2018-Priscilla-Ism演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郑秀文.1999-我应该得到(国)【华纳】【WAV+CUE】
- 陈家慧.2011-钢琴酒吧2CD【龙吟唱片】【WAV+CUE】
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[320K/MP3][45.01MB]
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[FLAC/分轨][109.13MB]
- 赞多《序章》[320K/MP3][45.54MB]
- 许巍.2004-每一刻都是崭新的【步升大风】【WAV+CUE】
- 群星.2024-四方馆影视原声带【韶愔音乐】【FLAC分轨】
- 陈雷.1997-安锁咧【金圆唱片】【WAV+CUE】
- 关淑怡.2013-MY.FAVORITE.SK.3CD【环球】【WAV+CUE】
- Sweety.2006-花言乔语【丰华】【WAV+CUE】