python:单元测试框架pytest的一个简单例子
之前一般做自动化测试用的是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报告中

python:单元测试框架pytest的一个简单例子的更多相关文章
- python单元测试框架pytest
首先祝大家国庆节日快乐,这个假期因为我老婆要考注会,我也跟着天天去图书馆学了几天,学习的感觉还是非常不错的,这是一篇总结. 这篇博客准备讲解一下pytest测试框架,这个框架是当前最流行的python ...
- python单元测试框架——pytest
官网:https://docs.pytest.org/en/latest/ pytest帮你写出更好的程序 1.An example of a simple test:(一个简单的例子),命名为tes ...
- 【Pytest】python单元测试框架pytest简介
1.Pytest介绍 pytest是python的一种单元测试框架,与python自带的unittest测试框架类似,但是比unittest框架使用起来更简洁,效率更高.根据pytest的官方网站介绍 ...
- python单元测试框架pytest——fixture函数(类似unitest的setup和teardown)
pytest的setup和teardown函数(曾被一家云计算面试官问到过). pytest提供了fixture函数用以在测试执行前和执行后进行必要的准备和清理工作.与python自带的unitest ...
- Python单元测试框架pytest常用测试报告类型
先前博客有介绍pytest测试框架的安装及使用,现在来聊聊pytest可以生成哪些测试报告 1.allure测试报告 关于allure报告参见先前的一篇博文:https://www.cnblogs.c ...
- Python单元测试框架之pytest 4 -- 断言
From: https://www.cnblogs.com/fnng/p/4774676.html Python单元测试框架之pytest -- 断言 2015-08-31 23:57 by 虫师, ...
- Python单元测试框架之pytest 3 -- fixtures
From: https://www.cnblogs.com/fnng/p/4769020.html Python单元测试框架之pytest -- fixtures 2015-08-29 13:05 b ...
- Python单元测试框架之pytest 2 -- 生成测试报告
From: https://www.cnblogs.com/fnng/p/4768239.html Python单元测试框架之pytest -- 生成测试报告 2015-08-29 00:40 by ...
- python单元测试框架笔记
目录 单元测试概述 什么是单元测试 单元测试什么进行? 单元测试由谁负责? 单元测试需要注意 单元测试覆盖类型 python 单元测试框架 unittest pytest 测试框架 单元测试概述 什么 ...
随机推荐
- ARTS-week3
Algorithm 给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度.不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件 ...
- datebox设置默认时间
1. html代码: <input id="txtBeginTime" class="easyui-datebox" data-options=" ...
- Python 简单批量请求接口实例
#coding:utf-8 ''' Created on 2017年11月10日 @author: li.liu ''' import urllib import time str1=''' http ...
- Alpha冲刺随笔九:第九天
课程名称:软件工程1916|W(福州大学) 作业要求:项目Alpha冲刺(十天冲刺) 团队名称:葫芦娃队 作业目标:在十天冲刺里对每天的任务进行总结. 随笔汇总:https://www.cnblogs ...
- js添加触摸时间,禁止页面缩放
<meta name="viewport" content="target-densitydpi=320,width=640,user-scalable=no&qu ...
- git和bootstrap
在linux系统中某种类型的服务有没有启动:ps -ef|grep 对应的服务名称 然后修改gitlab中的两个配置文件的信息 一般情况下是先创建组,然后在创建项目 常见的协议有http协议 ss ...
- linux /lib64/libc.so.6: version `GLIBC_2.17′ not found
使用root权限安装Glances,需要用到glibc,安装失败后所有命令都不好用了,执行回报“/lib64/libc.so.6: version `GLIBC_2.17′ not found ”的错 ...
- VISIO 2016安装破解
VISIO 2016安装破解 安装包下载 (2.41G) 安装包下载地址 :https://msdn.itellyou.cn/ ed2k://|file|cn_visio_professional_2 ...
- C Primer Plus--高级数据结构之二叉树
目录 二叉搜索树 Binary Search Tree 用C构建二叉树ADT 树结构的定义 C Primer Plus--高级数据结构表示之二叉树 二叉搜索树 Binary Search Tree 二 ...
- 框架 get 请求乱码
解决方案: 在 tomcat 配置文件中添加 URIEncoding="utf-8"