当前位置: 首页 > news >正文

【pytest】conftest.py使用

1. 创建test_project 目录

test_project/sub/test_sub.py

def test_baidu(test_url):print(f'sub ={test_url}')

test_project/conftest.py  设置钩子函数  只对当前目录 和子目录起作用

import pytest
#设置测试钩子函数
@pytest.fixture()
def test_url():return  "https://www.baidu.com"

test_project/test_demo.py

def test_baidu(test_url):print(test_url)

运行 

 pytest -s -v ./test_project

或 main 运行

import pytestif __name__=='__main__':#pytest.main(['-s','./fixture'])#pytest.main(['-v', './fixture','--junit-xml=./report/log.xml'])#pytest.main(['-v', './fixture', '--pastebin=all'])pytest.main(['-v','-s' ,'./test_project', '--pastebin=all'])
plugins: anyio-3.5.0
collecting ... collected 2 itemstest_project/test_demo.py::test_baidu https://www.baidu.com
PASSED
test_project/sub/test_sub.py::test_baidu sub =https://www.baidu.com
PASSED============================== 2 passed in 0.05s ==============================
==================== Sending information to Paste Service =====================
pastebin session-log: https://bpa.st/show/H4UQ

http://www.lryc.cn/news/175241.html

相关文章:

  • SpringBoot集成Prometheus实现监控
  • 【操作系统笔记十】缓存一致性
  • lS1028 + 六网口TSN 硬交换+QNX/Linux实时系统解决方案在轨道交通系统的应用
  • 实现字符串反转函数
  • 抽检监测实施
  • C++中的静态库与动态库
  • UGUI 绘制线段
  • 详细学习Mybatis(2)
  • LinkedList与链表
  • 纳米软件芯片自动化测试系统测试电源芯片稳压反馈的方法
  • 微信小程序之项目基本结构、页面的基础及宿主环境
  • C/C++鸡尾酒疗法 2023年5月电子学会青少年软件编程(C/C++)等级考试一级真题答案解析
  • 人工智能及大模型简介
  • 基于springboot消防员招录系统
  • 手把手教你制作登录、注册界面 SpringBoot+Vue.js(cookie的灵活运用,验证码功能)
  • C++ Qt零基础入门进阶与企业级项目实战教程与学习方法分享
  • TypeScript学习记录
  • vue内置组件Transition的详解
  • 中秋节听夜曲,Android OpenGL 呈现周董专属的玉兔主题音乐播放器
  • 008_第一代软件系统架构
  • oracle客户端的安装(SQL Developer)
  • Mysql索引优化1
  • Spring常考知识点(IOC、事务、容器等)
  • Leetcode 2867. Count Valid Paths in a Tree
  • Jtti:Ubuntu下如何创建XFS文件系统的LVM
  • 做销售管理分析需要看哪些关键指标?
  • 【Python】自动完成手写字体图片贴入以及盖章工具
  • 基于Xml方式Bean的配置-初始化方法和销毁方法
  • 实时更新进度条:JavaScript中的定时器和异步编程技巧
  • 【简单图论】CF898 div4 H