pytest fixture夹具,@pytest.fixture

fixture 是pytest 用于测试前后进行预备,清理工作的代码处理机制

fixture相对于setup 和teardown:

fixure ,命名更加灵活,局限性比较小

conftest.py 配置里面可以实现数据共享,不需要import 就能自动找到一些配置

setup / teardown

模块级 setup_module / teardown_module 开始于模块始末,生效一次

函数级 setup_function / teardown_function 对每条函数用例生效 (不在类中)

类级 setup_class / teardown_class 只在类中前后运行一次 (在类中)

方法级 setup_method / teardown_method 开始于方法始末 (在类中)

(scop="function") 每一个函数或方法都会调用

(scop="class") 每一个类调用一次

(scop="module") 每一个.py文件调用一次

(scop="session") 是多个文件调用一次,.py文件就是module

fixture的作用范围:session>module>class>function

相关推荐
5:001 天前
pytest框架-详解
pytest
丿罗小黑4 天前
Pytest项目_day15(yaml)
pytest
丿罗小黑4 天前
Pytest项目_day16(yaml和parametrize结合)
pytest
代码小念5 天前
Pytest+selenium UI自动化测试实战实例(超详细)
selenium·ui·pytest
丿罗小黑5 天前
Pytest项目_day11(fixture、conftest)
pytest
测试开发技术10 天前
软件测试中,pytest 运行完成后,如何自动发送邮件?
开发语言·python·pytest·接口测试·面试题
丿罗小黑10 天前
Pytest项目_day08(setup、teardown前置后置操作)
pytest
测试199810 天前
Pytest中实现自动生成测试用例脚本代码
自动化测试·软件测试·python·测试工具·测试用例·pytest·接口测试