之前一般做自动化测试用的是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的一个简单例子的更多相关文章

  1. python单元测试框架pytest

    首先祝大家国庆节日快乐,这个假期因为我老婆要考注会,我也跟着天天去图书馆学了几天,学习的感觉还是非常不错的,这是一篇总结. 这篇博客准备讲解一下pytest测试框架,这个框架是当前最流行的python ...

  2. python单元测试框架——pytest

    官网:https://docs.pytest.org/en/latest/ pytest帮你写出更好的程序 1.An example of a simple test:(一个简单的例子),命名为tes ...

  3. 【Pytest】python单元测试框架pytest简介

    1.Pytest介绍 pytest是python的一种单元测试框架,与python自带的unittest测试框架类似,但是比unittest框架使用起来更简洁,效率更高.根据pytest的官方网站介绍 ...

  4. python单元测试框架pytest——fixture函数(类似unitest的setup和teardown)

    pytest的setup和teardown函数(曾被一家云计算面试官问到过). pytest提供了fixture函数用以在测试执行前和执行后进行必要的准备和清理工作.与python自带的unitest ...

  5. Python单元测试框架pytest常用测试报告类型

    先前博客有介绍pytest测试框架的安装及使用,现在来聊聊pytest可以生成哪些测试报告 1.allure测试报告 关于allure报告参见先前的一篇博文:https://www.cnblogs.c ...

  6. Python单元测试框架之pytest 4 -- 断言

    From: https://www.cnblogs.com/fnng/p/4774676.html Python单元测试框架之pytest -- 断言 2015-08-31 23:57 by 虫师, ...

  7. Python单元测试框架之pytest 3 -- fixtures

    From: https://www.cnblogs.com/fnng/p/4769020.html Python单元测试框架之pytest -- fixtures 2015-08-29 13:05 b ...

  8. Python单元测试框架之pytest 2 -- 生成测试报告

    From: https://www.cnblogs.com/fnng/p/4768239.html Python单元测试框架之pytest -- 生成测试报告 2015-08-29 00:40 by ...

  9. python单元测试框架笔记

    目录 单元测试概述 什么是单元测试 单元测试什么进行? 单元测试由谁负责? 单元测试需要注意 单元测试覆盖类型 python 单元测试框架 unittest pytest 测试框架 单元测试概述 什么 ...

随机推荐

  1. appium+python自动化64-使用Uiautomator2执行driver.keyevent()方法报错解决

    前言 未加'automationName': 'Uiautomator2'参数使用Uiautomator可以正常使用driver.keyevent()方法,使用Uiautomator2时driver. ...

  2. 删除线性表中所有值为x的元素

    时间复杂度O(n),空间复杂度O(1). 简单的问题两种不同的思路. 代码: #include <stdio.h> #define MAX 100 struct sqlist{ int d ...

  3. Linux系统文件/etc/fstab

    挂载可以使用命令或者修改系统文件两种方式,第一种方式使用mount命令挂载文件系统可以立即生效并使用,但计算机重启后无效.另一种方式需要修改系统文件/etc/fstab,这种方式挂载的文件系统在计算机 ...

  4. test20190924 老L

    80+50+100=230.T1没做出来说明我数列学得不好? LOLO 的含树 现有函数 \[ g_m(i)=\begin{cases} 0, & 0 \leq i \leq m\\ i-1+ ...

  5. Spring源码窥探之:单实例Bean的创建过程

    finishBeanFactoryInitialization(beanFactory);初始化剩下的所有的单实例(非懒加载)Bean(Instantiate all remaining (non-l ...

  6. LeetCode 1011. Capacity To Ship Packages Within D Days

    原题链接在这里:https://leetcode.com/problems/capacity-to-ship-packages-within-d-days/ 题目: A conveyor belt h ...

  7. LeetCode 959. Regions Cut By Slashes

    原题链接在这里:https://leetcode.com/problems/regions-cut-by-slashes/ 题目: In a N x N grid composed of 1 x 1 ...

  8. go选项模式

    package main import "fmt" type optionClient func(*options) func setAge(a int) optionClient ...

  9. walk

    一个go做gui的包, 可以配置程序图标 编译运行需要...fest文件 rsrc

  10. SDN阅读作业

    阅读文章<软件定义网络(SDN)研究进展>,并根据所阅读的文章,书写一篇博客,回答以下问题(至少3个): 1.为什么需要SDN?SDN特点? 随着网络规模的不断扩大,传统网络设备繁复的协议 ...