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

相关推荐
旦莫1 天前
Pytest教程: Pytest ini配置文件深度剖析
python·单元测试·自动化·pytest
Mr_Xuhhh5 天前
pytest -- 测试报告allure
pytest
我的xiaodoujiao6 天前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 28--开源电商商城系统项目实战--封装注册页面
python·学习·测试工具·pytest
Mr_Xuhhh7 天前
pytest -- fixture
开发语言·python·pytest
Mr_Xuhhh7 天前
pytest -- 指定⽤例执⾏顺序
开发语言·python·pytest
Mr_Xuhhh7 天前
pytest -- ⽇志与测试报告
pytest
西游音月9 天前
(5)pytest+Selenium自动化测试-元素定位之XPath定位
selenium·测试工具·pytest
西游音月11 天前
(4)pytest+Selenium自动化测试-元素定位之CSS Selector定位
css·selenium·pytest
淼_@淼12 天前
pytest-数据驱动
pytest