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

相关推荐
X1A0RAN1 天前
自动化流水线提效·微观篇:pytest 执行顺序优化
自动化·pytest
久久学姐9 天前
Python+Playwright+Pytest+BDD,用FSM打造高效测试框架
python·pytest·bdd·playwright·fsm
小白上线*^_^*9 天前
Pytest 自动化测试框架速通指南(二)
软件测试·pytest·python测试框架·ai测试基础
Logintern0910 天前
pytest的AST 断言重写
pytest
Tinyfacture11 天前
接口自动化之添加商品(pytest)
python·测试工具·自动化·pytest
ji_shuke13 天前
从零深入:基于 Playwright + Pytest + Allure 的企业级 Web 端到端自动化测试框架实战
前端·自动化测试·docker·jenkins·pytest·allure·playwright
祉猷并茂,雯华若锦14 天前
Selenium+Pytest自动化测试框架实战
selenium·测试工具·pytest
祉猷并茂,雯华若锦15 天前
Pytest+Selenium自动化测试:失败自动截图集成Allure报告
selenium·测试工具·pytest
我的xiaodoujiao19 天前
API 接口自动化测试详细图文教程学习系列32--Allure测试报告2
python·学习·测试工具·pytest
一孤程22 天前
Pytest+Selenium搭建自动化框架-保姆级实战教程
selenium·自动化·pytest