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

相关推荐
糖果店的幽灵14 天前
软件测试接口测试从入门到精通:Python接口自动化 - pytest测试框架
软件测试·python·功能测试·自动化·pytest·接口测试
2601_9618752415 天前
花生十三资料1200题|题库|刷题
conda·pytest·pillow·pip·web3.py·ipython·gunicorn
某人辛木15 天前
Web自动化测试
前端·python·pycharm·pytest
淡漠的蓝精灵17 天前
pytest-xdist:把 pytest 测试分发到多核 CPU 执行
其他·pytest
弹简特19 天前
【接口自动化】03-YAML详解及Parametrize数据驱动
自动化·pytest
007张三丰20 天前
软件测试专栏(11/20):测试框架开发:pytest深度解析与插件体系
运维·服务器·自动化测试·pytest·测试框架
我的xiaodoujiao21 天前
API 接口自动化测试详细图文教程学习系列25--继续处理testCase中的数据
python·学习·测试工具·pytest
xiaobai17821 天前
pytest+playwright实现UI自动化(4)-上夹具fixture
ui·自动化·pytest·playwright
弹简特22 天前
【接口自动化】02-Pytest固件fixture核心机制与Allure企业级报告实战
自动化·pytest·测试