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

相关推荐
摘星编程6 天前
AI 帮我写单测:pytest 覆盖率提升 40% 的协作日志
人工智能·pytest·测试驱动开发·代码覆盖率·ai协作开发
lucia_zl9 天前
pytest并发测试,资源问题导致用例失败解决办法
pytest
鱼鱼说测试9 天前
Selenium4+Pytest自动化测试框架实战
pytest
XYiFfang15 天前
【Pytest】解决Pytest中Teardown钩子的TypeError:实例方法与类方法的调用差异
python·pytest
Kingairy17 天前
Pytest 插件:pytest_runtest_protocol
python·pytest
AIZHINAN17 天前
Pytest 插件介绍和开发
测试工具·pytest·插件开发
灰阳阳19 天前
替身演员的艺术:pytest-mock 从入门到飙戏
自动化测试·python·pytest·unit testing·pytest-mock
年年测试22 天前
Playwright与PyTest结合指南
pytest
focksorCr23 天前
pytest 并发执行用例(基于受限的测试资源)
python·pytest