场景:你与其他测试工程师合作一起开发时,公共的模块要在不同文件中,要

在大家都访问到的地方。

  • 解决:使用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,登陆后执行支付功能操作

最新文章

  1. PG CREATEINDEX CONCURRENTLY
  2. PHPMySQL 中 pdo文件的增删改查
  3. 解决ecshop在线客户点击无法唤醒QQ问题
  4. sort如何按指定的列排序·百家电脑学院
  5. srping标签和hibernate查询
  6. 前端笔记----jquery入门知识点总结
  7. [Link-Cut-Tree]【学习笔记】
  8. 福利:工作经常用到的Mac软件整理(全)
  9. IE9以及以下不支持jquery ajax跨域问题
  10. spring xml配置注入改为手动注入过程
  11. JAVA基础知识笔记
  12. linux内核分析第六周学习笔记
  13. Addition Chains
  14. gzip0
  15. ST表的原理及其实现
  16. python中 除了if else def class 有作用域 其余没有作用域
  17. vSphere Data Protection – a new backup product included with vSphere 5.1
  18. 全局唯一ID生成器
  19. 浅学html
  20. 使用matplotlib的示例:调整字体-设置colormap和colorbar

热门文章

  1. SSO 实现博客系统的单点登录
  2. InnoDB B树 锁
  3. Could not autowire. No beans of 'int' type found. less... (Ctrl+F1) Checks autowiring problems in a bean class.
  4. 微信小程序のwxss选择器
  5. 检查目录下 文件的权限-linux shell脚本
  6. Java连接ActiveMQ代码示例(Producer和Consumer)
  7. linux配置java环境变量(详细)(转)
  8. springboot集成使用rabbitmq笔记(1.rabbitmq安装)
  9. yarn安装node-sass报错问题
  10. SQL复制数据表及表结构