首页 > 其他分享 >PyTestReport-0.1.9版本更新

PyTestReport-0.1.9版本更新

时间:2022-12-20 11:40:14浏览次数:39  
标签:API __ PyTestReport 0.1 html -- pytest 版本 report


文章目录

  • ​​多了哪些功能呢?​​
  • ​​如何与PyTest框架结合使用​​
  • ​​如何通过API的方式生成报告​​
  • ​​如何生成图片报告并发送邮件​​
  • ​​新书推荐​​


还记得那个发布不就的Python单元测试报告框架么?噢!如果不记得那我今天就再来说一篇吧!_ PyTestReport 0.1.9版本正式发布了!

多了哪些功能呢?

  • 增加对PyTest框架的支持(目前可以支持unittest、pytest两大框架)
  • 增加了支持通过lib API接口的方式生成测试报告(前提是把报告数据整理成要求的格式)
  • 增加了HTML报告转图片报告的API
  • 增加了发送邮件功能的API
  • 修复了一些bug!这些是自然的!
  • 规范了一些数据格式的字段和内容

接下来,请坐好小板凳,我准备带你们飞了!!!

如何与PyTest框架结合使用

对于pytest框架,收集其测试结果信息是通过pytest插件形式实现的。使用之前只要确保正常安装了PyTestReport即可。具体使用方式如下:

import pytest

def testTrue():
assert True

def testFalse():
assert False

def testError():
1 / 0

@pytest.mark.skip(reason="misunderstood the API")
def testSkip():
assert 1 == 1

@pytest.mark.xfail(reason="Xpass")
def testXPass():
assert True

@pytest.mark.xfail(reason="Xfail")
def testXFail():
assert False


if __name__ == '__main__':
pytest.main(["-s", "pytest_Demo.py", "--pytest_report", "Pytest_Report.html"])

需要注意的是,pytest框架想要使用本测试报告框架,在调用时需要带上​​--pytest_report​​参数,并指定一个报告的文件路径即可。当然你也可以同时指定一个非默认主题。比如:

import pytest

if __name__ == '__main__':
pytest.main(["-s", "pytest_Demo.py", "--pytest_report", "Pytest_Report.html",
"--pytest_title", "report title", "--pytest_desc", "report desc",
"--pytest_theme", "new_theme"])

另外,你也可以通过命令行的方式来启动pytest执行单元测试。比如:

pytest -s pytest_Demo.py --pytest_report Pytest_Report.html --pytest_theme new_theme

如何通过API的方式生成报告

from pytestreport.api import make_report

data = {
"generator": "PyTestReport 0.1.4",
"title": "默认主题",
"description": "默认主题描述",
"report_summary": {
"start_time": "2019-05-12 23:07:49",
"duration": "0:00:00.002000",
"suite_count": 1,
"status": {
"pass": 1,
"fail": 0,
"error": 0,
"skip": 0,
"count": 1
}
},
"report_detail": {
"tests": [
{
"summary": {
"desc": "utDemo.UTestPass",
"count": 1,
"pass": 1,
"fail": 0,
"error": 0,
"skip": 0,
"cid": "testclass1",
"status": "pass"
},
"detail": [
{
"has_output": False,
"tid": "testpass.1.1",
"desc": "testTrue",
"output": "",
"status": "pass",
"status_code": 0
}
]
}
],
"count": "1",
"pass": "1",
"fail": "0",
"error": "0",
"skip": "0"
}
}
with open('API_Report.html', 'wb') as fp:
make_report(fp, data)
# will be create API_Report.html file at current directory.

同样的,你也可以指定特定的主题或者样式。比如:

...
with open('API_Report.html', 'wb') as fp:
make_report(fp, data, theme='new_theme', stylesheet='new_stylesheet_2.css')

如何生成图片报告并发送邮件

from pytestreport.api import make_image, send_report

html = r"D:\test\report.html"
image = r"D:\test\report.png"
make_image(html, image)
# will be generate "report.png" file at "D:\test\".

send_report("subject", html, image, "[email protected]", ["[email protected]"], cc=["[email protected]"])
# will be send image content email with html as attach accordingly.

新书推荐

PyTestReport-0.1.9版本更新_python

获取更多关于Python和自动化测试的文章,请扫描如下二维码!

PyTestReport-0.1.9版本更新_pytest_02

标签:API,__,PyTestReport,0.1,html,--,pytest,版本,report
From: https://blog.51cto.com/u_15918230/5954615

相关文章

  • Python单元测试报告框架PyTestReport
    文章目录开局一张图安装通过pip安装通过安装包通过源码(最新版本)使用单元测试使用样例附录​​原文链接​​如果你是Java栈的同学,那么你可能知道extentreport测试报告框架。......
  • 【转载】用shell命令一步步获取Java版本号
    https://blog.csdn.net/f20052604/article/details/100269768 1、打印java-version命令echo$(java-version)输出javaversion"1.8.0_171"Java(TM)SERuntimeEnvi......
  • Mac m1修改默认java版本,降版本方法
    最近通过各种途径安装了许多jdk版本,1.7、1.8、11、13、17等 结果系统默认的java-version最终变成了17,通过各种环境变量设置都无法修改成别的版本 再网上找了许多......
  • java JVM和class字节码版本对照表
    链接前往JDKVersionBytecodeVersionJava1.045.0Java1.145.3Java1.246.0Java1.347.0Java1.448.0Java549.0Java650.0Java7......
  • Osx10.14升级watchman踩坑记
    背景使用watchman检测文件变化通知非常的好用,但有些时候会出现watchman占用内存和CPU特别疯狂,通过watch-del也无济与事,由于watchman的版本2021.09.13比......
  • MySQL 8.0.0 版本发布,亮点都在这了!
    MySQL是一个开放源码的小型关联式数据库管理系统,开发者为瑞典MySQLAB公司。目前MySQL被广泛地应用在Internet上的中小型网站中。由于其体积小、速度快、总体拥有成本低......
  • Osx10.14升级watchman踩坑记
    背景使用​​watchman​​检测文件变化通知非常的好用,但有些时候会出现watchman占用内存和CPU特别疯狂,通过​​watch-del​​也无济与事,由于watchman的版本......
  • 细说集中式与分布式版本控制系统
    前言:分布式版本控制系统除了Git以及促使Git诞生的BitKeeper外,还有类似Git的Mercurial和Bazaar等。这些分布式版本控制系统各有特点,但最快、最简单也最流行的依然是Git!集中式......
  • ubuntu下升级特定软件与查看软件版本信息
    机器学习以及人工智能的学习需要扎实的数学功底才能走的更远,爬的更高,所以打好数学基础是关键,但无论工作学习都没有充足的时间去拿着书本一个字一个字的去学习了,这里我建议大......
  • git 如何让单个文件回退到指定的版本
    1.进入到文件所在文件目录,或者能找到文件的路径查看文件的修改记录$gitlogMainActivity.java结果:commit7641210b242a95eed17827dd8159e76bdad6d619Author:ronanhardima......