<5>pytest:前置后置
2021/12/5 6:17:26
本文主要是介绍<5>pytest:前置后置,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
总览
执行顺序
类外
setup_moudle setup_function case teardown_function teardown_moudle
类中
setup_moudle setup_class setup_method setup case teardown teardown_method teardown_class teardown_moudle
代码举例
代码
def setup_module(): print("\nsetup_module") def teardown_module(): print("teardown_module") def setup_function(): print("\nsetup_function") def teardown_function(): print("teardown_function") def test_case1(): print("测试用例_函数1") def test_case2(): print("测试用例_函数2") class TestClass: def setup_class(self): print("\nsetup_class") def teardown_class(self): print("teardown_class") def setup_method(self): print("\nsetup_method") def teardown_method(self): print("teardown_method") def setup(self): print("setup") def teardown(self): print("teardown") def test_class_case1(self): print("测试用例_类_方法1") def test_class_case2(self): print("测试用例_类_方法2")
输出
============================= test session starts ============================= collecting ... collected 4 items setup_and_teardown.py::test_case1 setup_module setup_function PASSED [ 25%]测试用例_函数1 teardown_function setup_and_teardown.py::test_case2 setup_function PASSED [ 50%]测试用例_函数2 teardown_function setup_and_teardown.py::TestClass::test_class_case1 setup_class setup_method setup PASSED [ 75%]测试用例_类_方法1 teardown teardown_method setup_and_teardown.py::TestClass::test_class_case2 setup_method setup PASSED [100%]测试用例_类_方法2 teardown teardown_method teardown_class teardown_module ============================== 4 passed in 0.03s ============================== 进程已结束,退出代码为 0
这篇关于<5>pytest:前置后置的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-02Java管理系统项目实战入门教程
- 2024-11-02Java监控系统项目实战教程
- 2024-11-02Java就业项目项目实战:从入门到初级工程师的必备技能
- 2024-11-02Java全端项目实战入门教程
- 2024-11-02Java全栈项目实战:从入门到初级应用
- 2024-11-02Java日志系统项目实战:初学者完全指南
- 2024-11-02Java微服务系统项目实战入门教程
- 2024-11-02Java微服务项目实战:新手入门指南
- 2024-11-02Java项目实战:新手入门教程
- 2024-11-02Java小程序项目实战:从入门到简单应用