python:单元测试框架pytest的一个简单例子
2024-10-19 18:42:40
之前一般做自动化测试用的是unitest框架,发现pytest同样不错,写一个例子感受一下
test_sample.py
import cx_Oracle
import config
from send_message import send_message
from insert_cainiao_oracle import insert_cainiao_oracle def test_cainiao_monitor():
"""
查询数据库信息对比数据是否满足要求,如不满足则发送短信通知,并写入数据库。
:return:
"""
sql = "select COUNT(*) from AVGINDEX t WHERE t.STATDATE = '2019-09-11'" conn = cx_Oracle.connect(config.name, config.password, config.host_port_sid)
cursor = conn.cursor()
cursor.execute(sql)
data = cursor.fetchall()
print(data)
print(data[0][0])
conn.commit()
cursor.close() # 关闭游标
conn.close() # 关闭数据库连接 try:
assert data[0][0] == 18
# 如断言失败,则会抛出AssertionError异常,将此异常捕获,继续执行下面的发送短信和插入数据库操作,
# 如果不捕获则断言失败后不继续执行下方代码
except AssertionError as e:
print('断言失败了')
print(e)
content = '查询结果为%s条,不等于18条!' % data[0][0]
# 发短信方法
send_message(content, [18*********])
# 信息入库方法
insert_cainiao_oracle(1, content)
执行命令:
pytest test_sample.py --html=report.html
执行test_sample.py这个文件中的所有测试函数,并将执行结果输出到report.html报告中
最新文章
- Windows Server 2012 虚拟化实战:网络(一)
- webuploader在IE8/9下上传遇到的两个问题
- Anliven - 基础知识梳理汇总 - 软件测试
- 1.2 ASSEMBLY LANGUAGE
- scope='request'的bean预加载冲突
- C/C++中static关键字详解
- 全新重装win8.1系统后 配置开发及办公环境步骤
- 通过Sql语句导数据
- L1 - 运行机制
- WordPress搭建Personal Blog 个人博客
- js dom
- hiho拓扑排序专题 ——第四十八、四十七周
- js 判断微信浏览器(转)
- A Distributed Multichannel MAC Protocol for Multihop Cognitive Radio Networks
- Navicat工具Oracle数据库复制 or 备用、恢复功能(评论都在谈论需要教)
- strncmp函数——比较特定长度的字符串
- vim+makefile入门编辑,编译,差错实例
- idea 找不到classpath 为resource下的xml
- opencv利用hough概率变换拟合得到直线后,利用DDA算法得到直线上的像素点坐标
- Runnable和Callable接口辨析