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

相关推荐
一个处女座的测试7 小时前
Python语言+pytest框架+allure报告+log日志+yaml文件+mysql断言实现接口自动化框架
python·mysql·pytest
思则变3 天前
[Pytest][Part 1]Pytest 自动化测试框架
pytest
思则变5 天前
[Pytest] [Part 2]增加 log功能
开发语言·python·pytest
思则变5 天前
[Pytest][Part 3]检测python package状态
pytest
cooldream200919 天前
pytest 框架详解与实战指南
pytest·测试
慕城南风19 天前
【pytest进阶】Pytest之conftest详解
pytest
编程小白gogogo20 天前
AI自动化测试速成(Pytest框架)
pytest
慕城南风20 天前
【pytest进阶】pytest详解及进阶使用
linux·服务器·pytest
Tom Boom1 个月前
Pytest断言全解析:掌握测试验证的核心艺术
自动化测试·python·测试开发·pytest