pytest_fixture-----conftest共享数据及不同层次共享
2024-09-06 05:09:28
场景:你与其他测试工程师合作一起开发时,公共的模块要在不同文件中,要
在大家都访问到的地方。
解决:使用conftest.py 这个文件进行数据共享,并且他可以放在不同位置起 着不同的范围共享作用。
前提:conftest文件名是不能换的,放在项目下是全局的数据共享的地方,全 局的配置和前期工作都可以写在这里,放在某个包下,就是这个包数据共享的 地方。
执行:系统执行到参数login时先从本文件中查找是否有这个名字的变量什么 的,之后在conftest.py中找是否有。
步骤:将登陆模块带@pytest.fixture写在conftest.py
conftest.py下面的代码:
import pytest
@pytest.fixture()
def login():
print("\n输入用户名密码登陆! configtest")
pytest_fixture下面的代码:
def test_cart(login):
print('用例1,登陆后执行添加购物车功能操作') def test_search():
print('用例2,不登陆查询功能操作') def test_pay(login):
print('用例3,登陆后执行支付功能操作') 执行结果:
ytest_fixture.py::test_cart
输入用户名密码登陆! configtest
PASSED [ 33%]用例1,登陆后执行添加购物车功能操作
pytest_fixture.py::test_search PASSED [ 66%]用例2,不登陆查询功能操作
pytest_fixture.py::test_pay
输入用户名密码登陆! configtest
PASSED [100%]用例3,登陆后执行支付功能操作
最新文章
- PG CREATEINDEX CONCURRENTLY
- PHPMySQL 中 pdo文件的增删改查
- 解决ecshop在线客户点击无法唤醒QQ问题
- sort如何按指定的列排序·百家电脑学院
- srping标签和hibernate查询
- 前端笔记----jquery入门知识点总结
- [Link-Cut-Tree]【学习笔记】
- 福利:工作经常用到的Mac软件整理(全)
- IE9以及以下不支持jquery ajax跨域问题
- spring xml配置注入改为手动注入过程
- JAVA基础知识笔记
- linux内核分析第六周学习笔记
- Addition Chains
- gzip0
- ST表的原理及其实现
- python中 除了if else def class 有作用域 其余没有作用域
- vSphere Data Protection – a new backup product included with vSphere 5.1
- 全局唯一ID生成器
- 浅学html
- 使用matplotlib的示例:调整字体-设置colormap和colorbar
热门文章
- SSO 实现博客系统的单点登录
- InnoDB B树 锁
- Could not autowire. No beans of 'int' type found. less... (Ctrl+F1) Checks autowiring problems in a bean class.
- 微信小程序のwxss选择器
- 检查目录下 文件的权限-linux shell脚本
- Java连接ActiveMQ代码示例(Producer和Consumer)
- linux配置java环境变量(详细)(转)
- springboot集成使用rabbitmq笔记(1.rabbitmq安装)
- yarn安装node-sass报错问题
- SQL复制数据表及表结构