使用 HTMLTestRunner 模块生成HTML格式的测试报告文件
1.下载HTMLTestRunner.py
HTMLTestRunner 是 Python 标准库的 unittest 模块的一个扩展。它生成易于使用的 HTML 测试报告。HTMLTestRunner 是在 BSD 许可证下发布。
(1)下载 地址:http://tungwaiyip.info/software/HTMLTestRunner.html -->
(2)点击HTMLTestRunner.py进入目标文件后,右键另存于即可。
(3)python3中用HTMLTestRunner.py报ImportError: No module named ‘StringIO‘的解决方法:
第94行,将import StringIO修改成import io
第539行,将self.outputBuffer = StringIO.StringIO()修改成self.outputBuffer = io.StringIO()
第642行,将if not rmap.has_key(cls):修改成if not cls in rmap:
第766行,将uo = o.decode(‘latin-1‘)修改成uo = e
第772行,将ue = e.decode(‘latin-1‘)修改成ue = e
第631行,将print >> sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime)修改成print(sys.stderr, '\nTime Elapsed: %s' % (self.stopTime-self.startTime))
(4)修改后下载链接: https://pan.baidu.com/s/13vLRRq9IB2B2y-OwTWrepg 提取码: 89pd
Windows :将下载的文件放入Python34的安装目录...\Python34\Lib 目录下
2.导入 htmltestrunner 模块包
from HTMLTestRunner import HTMLTestRunner
import unittest
from time import strftime 或者import time,datetime
import os
from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart # 邮件格式 from email.mime.image import MIMEImage # 发送带图片邮件
3.定义测试用例路径
test_dir = './testcase/'
或者
list_1 = 'test_case\\testcase'
4.查找元素(testcase)
discover = unittest.defaultTestLoader.discover(test_dir,'*case.py')
5.定义测试报告文件名以及取前面时间加入到测试报告文件名中
# 定义报告存放路径,支持相对路径
file_name = './report/' + strftime('%Y_%m_%d_%H_%M_%S') + '.html'
6.创建文件
fp = open(file_name,'wb')
HTMLTestRunner(stream=fp,description='描述',title='标题').run(discover)
7.关闭文件
fp.close()
附件:
# -*- coding: utf-8 -*- import unittest
from HTMLTestRunner import HTMLTestRunner
import time,os,datetime
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.image import MIMEImage # 取test_case文件夹下所有用例文件
def creatsuitel(lists):
testunit = unittest.TestSuite()
# discover 方法定义
discover = unittest.defaultTestLoader.discover(lists, pattern='start_*.py', top_level_dir=None)
#discover 方法筛选出来的用例,循环添加到测试套件中
for test_suite in discover:
for test_case in test_suite:
testunit.addTests(test_case)
print(testunit)
return testunit
list_1 = 'test_case\\test_case_1'
alltestnames = creatsuitel(list_1) #取前面时间加入到测试报告文件名中
now = time.strftime("%Y-%m-%M-%H_%M_%S", time.localtime(time.time()))
filename = "report\\"+now+'result.html' #定义个报告存放路径,支持相对路径。
fp = open(filename, 'wb')
runner = HTMLTestRunner(stream=fp, title='Report_title', description='Report_description') if __name__ == "__main__":
# 执行测试用例集并生成报告
runner = unittest.TextTestRunner()
使用 HTMLTestRunner 模块生成HTML格式的测试报告文件的更多相关文章
- Python 中 使用 HTMLTestRunner 模块生成测试报告
使用 HTMLTestRunner 模块可以生成测试报告,但是系统自带的报告不详细,不好看,所以找了一份详细的报告 HTMLTestRunner 模板,直接导入就能使用 两种方法生成HTML报告,都 ...
- 使用HTMLTestRunner模块生成测试报告
步骤: 1.下载HTMLTestRunner模块 HTMLTestRunnerCN.py是中文版本的,EN是英文版本的,将要使用的版本放到Python安装目录下lib文件夹中,然后试试看能不能impo ...
- unittest中HTMLTestRunner模块生成
unittest里面是不能生成html格式报告的,需要导入一个第三方的模块:HTMLTestRunner 一.导入HTMLTestRunner 方法1.这个模块下载不能通过pip安装了,只能下载后手动 ...
- pytest.11.生成xml格式的测试报告
From: http://www.testclass.net/pytest/report/ pytest有非常友好的命令行报告输出,在做用例开发的时候,这是极好的.然而我们在运行用例后经常会需要将测试 ...
- Rss 订阅:php动态生成xml格式的rss文件
Rss 简介: 简易信息聚合(也 叫聚合内容)是一种描述和同步网站内容的格式.使用RSS订阅能更快地获取信息,网站提供RSS输出,有利于让用户获取网站内容的最新更新.网络用户可以在客户端借助于支持RS ...
- C#生成putty格式的ppk文件(支持passphrase)
背景 2022国家级护网行动即将开启,根据阿里云给出的安全建议,需要将登陆Linux的方式改为密钥对方式.我这里使用的远程工具是自己开发的,能够同时管理Windows和Linux,但是以前不支持密钥对 ...
- python模块学习之HTMLTestRunner模块生成HTML测试报告
#!/usr/bin/env python #-*- coding:utf-8 -*- from HTMLTestRunner import HTMLTestRunner import time im ...
- python3修改HTMLTestRunner,生成有截图的测试报告,并发送测试邮件(二)
3. 如何将第一步得到的地址和名称 输入 进第二步里的表格中呢... 用上述查找元素的方法,发现HTMLTestRunner.py中REPORT_TEST_WITH_OUTPUT_TMPL是用来输出测 ...
- Java生成xlsx格式的excel文件
xlsx格式的写入的数据量据说有百万级,结合实际需要该格式. public static void main(String[] args) throws Exception { OutputStrea ...
随机推荐
- [Hinton] Neural Networks for Machine Learning - Basic
Link: Neural Networks for Machine Learning - 多伦多大学 Link: Hinton的CSC321课程笔记1 Link: Hinton的CSC321课程笔记2 ...
- tomcat 下安装 MantisBT
环境 OS:win8.1 up1 64bit tomcat :9.0.0 64bit php: php-7.1.7-nts-Win32-VC14-x64.zip postgres: postgresq ...
- yum安装VirtualBox
参考官方文档: https://www.virtualbox.org/wiki/Linux_Downloads 配置yum源: vim /etc/yum.repos.d/virtualbox.repo ...
- 技巧:Vim 的纵向编辑模式
https://www.ibm.com/developerworks/cn/linux/l-cn-vimcolumn/ 开始之前 人类大脑对文字的处理是平面式的,所以我们浏览文章.查找资料或者重构代码 ...
- css3整理--background-size
background-size语法: /*Mozilla*/ -moz-background-size: auto || <length> || <percentage> || ...
- vscode 设置 cmder为终端
"terminal.integrated.shell.windows": "cmd.exe", "terminal.integrated.shellA ...
- mtd工具
http://daemons.net/linux/storage/mtd.html MTD The Memory Technology Devices (MTD) subsystem provides ...
- ASP.NET异步
1.ASP.NET线程模型 在WEB程序中,天生就是多线程的,我们知道,一个WEB服务可以同时服务器多个用户,我们可以想象一下,WEB程序应该运行于多线程环境中,对于运行WEB程序的线程,我们可以称之 ...
- The Structure of the Java Virtual Machine Java虚拟机结构 虚拟机内存模型
小结: 1.实现一台Java虚拟机,只需正确读取class文件中的每一条字节码指令且能正确执行这些指令所蕴含的操作. 2.设计者决定:运行时数据区的内存如何布局,选择哪种垃圾收集算法,是否对虚拟机字节 ...
- [development][PCRE] old PCRE
介绍, man手册 txt版 http://www.pcre.org/original/pcre.txt html版 http://www.pcre.org/original/doc/html/pcr ...