之前一般做自动化测试用的是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报告中

最新文章

  1. Windows Server 2012 虚拟化实战:网络(一)
  2. webuploader在IE8/9下上传遇到的两个问题
  3. Anliven - 基础知识梳理汇总 - 软件测试
  4. 1.2 ASSEMBLY LANGUAGE
  5. scope='request'的bean预加载冲突
  6. C/C++中static关键字详解
  7. 全新重装win8.1系统后 配置开发及办公环境步骤
  8. 通过Sql语句导数据
  9. L1 - 运行机制
  10. WordPress搭建Personal Blog 个人博客
  11. js dom
  12. hiho拓扑排序专题 ——第四十八、四十七周
  13. js 判断微信浏览器(转)
  14. A Distributed Multichannel MAC Protocol for Multihop Cognitive Radio Networks
  15. Navicat工具Oracle数据库复制 or 备用、恢复功能(评论都在谈论需要教)
  16. strncmp函数——比较特定长度的字符串
  17. vim+makefile入门编辑,编译,差错实例
  18. idea 找不到classpath 为resource下的xml
  19. opencv利用hough概率变换拟合得到直线后,利用DDA算法得到直线上的像素点坐标
  20. Runnable和Callable接口辨析

热门文章

  1. Lovers(HDU6562+线段树+2018年吉林站)
  2. Oracle中INSTR函数与SQL Server中CHARINDEX函数
  3. Laravel —— 路由问题
  4. java代码实现文件的下载功能
  5. shell脚本awk的基本用法
  6. windows系统的快速失败机制---fastfail
  7. dbt 0.14.0 试用
  8. The two of the oldest man need cheers
  9. 洛谷P3534 [POI2012] STU
  10. c博客作业-我的第一篇博客