使用unittest框架的脚本执行完成后,会生成一个html格式的报告

这个报告是提前制作了一个html的模板,然后将对应的内容写入到模板中,并生成一个最终的报告,这个报告模板在通过 pip install BeautifulReport后,就会在下面路径中存在:

C:\Program Files\Python37\Lib\site-packages\BeautifulReport\template,这个html模板可以将里面的一些表格属性名称修改为适合自己的名称,例如:

 <body class="gray-bg">
<div class="row border-bottom white-bg dashboard-header">
<div class="col-sm-12 text-center">
<span style="${title}">自动化测试报告</span>
</div>
</div>
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-sm-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5 style="${sub-title}">报告汇总</h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
<a class="close-link">
<i class="fa fa-times"></i>
</a>
</div>
</div>
<div class="ibox-content">
<div class="row">
<div class="col-sm-6 b-r" style="height:350px">
<form class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label text-info">测试目的:</label>
<div class="col-sm-5">
<span class="form-control" id="testName"></span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label text-info">用例总数:</label>
<div class="col-sm-5">
<span class="form-control" id="testAll"></span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label text-navy">用例通过:</label>
<div class="col-sm-5">
<span class="form-control" id="testPass"></span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label text-danger">用例失败:</label>
<div class="col-sm-5">
<span class="form-control text-danger" id="testFail"></span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label text-warning">用例跳过:</label>
<div class="col-sm-5">
<span class="form-control text-warning" id="testSkip"></span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label text-info">开始时间:</label>
<div class="col-sm-5">
<span class="form-control" id="beginTime"></span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label text-info">运行时间:</label>
<div class="col-sm-5">
<span class="form-control" id="totalTime"></span>
</div>
</div>
</form>
</div>
<div class="col-sm-6">
<div style="height:350px" id="echarts-map-chart"></div>
</div>
</div>
</div>
</div>
</div>
</div>

那么通过这个报告生成,都可以做哪些呢,比较指定存储路径,报告主题等,下面直接看BeautifulReport代码,发现要对这个类实例化时,必须要先传入一个suite(也就是测试用例集),然后调用这个类的report方法进行报告生成时,可以传入哪些参数:description, filename: str = None, report_dir='.', log_path=None, theme='theme_default',除去 log_path废弃后,可以有4个参数进行传入,每个参数的具体用法在代码中都有详细说明,这里不再重复。

 class BeautifulReport(ReportTestResult, PATH):
img_path = 'img/' if platform.system() != 'Windows' else 'img\\' def __init__(self, suites):
super(BeautifulReport, self).__init__(suites)
self.suites = suites
self.report_dir = None
self.title = '自动化测试报告'
self.filename = 'report.html' def report(self, description, filename: str = None, report_dir='.', log_path=None, theme='theme_default'):
"""
生成测试报告,并放在当前运行路径下
:param report_dir: 生成report的文件存储路径
:param filename: 生成文件的filename
:param description: 生成文件的注释
:param theme: 报告主题名 theme_default theme_cyan theme_candy theme_memories
:return:
"""
if log_path:
import warnings
message = ('"log_path" is deprecated, please replace with "report_dir"\n'
"e.g. result.report(filename='测试报告_demo', description='测试报告', report_dir='report')")
warnings.warn(message) if filename:
self.filename = filename if filename.endswith('.html') else filename + '.html' if description:
self.title = description self.report_dir = os.path.abspath(report_dir)
os.makedirs(self.report_dir, exist_ok=True)
self.suites.run(result=self)
self.stopTestRun(self.title)
self.output_report(theme)
text = '\n测试已全部完成, 可打开 {} 查看报告'.format(os.path.join(self.report_dir, self.filename))
print(text)

下面列举调用这个模块的实现方法:

 # -*- coding:utf-8 -*-
'''
# @Time : 2019/12/3 16:50
# @Author : nihaoya
# @FileName: WeiBo_test.py
# @Software: PyCharm
'''
import os
import time
import unittest
from BeautifulReport import BeautifulReport as bf class WeiBo(unittest.TestCase):
此处省略 if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromTestCase(WeiBo)
run = bf(suite)
run.report(filename=u"微博测试报告_" + time.strftime("%Y~%m~%d %H~%M~%S"), description=u"以游客形式浏览微博", report_dir="report", theme="theme_memories")

解读并加工BeautifulReport 报告模板的更多相关文章

  1. 单元测试unittest及报告生成(两种报告模板)

    Python中有一个自带的单元测试框架是unittest模块,用它来做单元测试,它里面封装好了一些校验返回的结果方法和一些用例执行前的初始化操作. 在说unittest之前,先说几个概念: TestC ...

  2. weblogic和was的巡检报告模板

    weblogic巡检报告模板  https://max.book118.com/html/2017/0710/121553357.shtm 用jrockit How to tell Our WebLo ...

  3. Beta 冲刺报告模板

    Beta 冲刺报告模板 十分钟左右站立会议,控制好时间,不要在此会议上讨论细节问题. 每组一份博客,组内共享,每人都需提交. 模板 队名:xxx 组员1(组长) 过去两天完成了哪些任务 文字/口头描述 ...

  4. Alpha 冲刺报告模板

    Alpha 冲刺报告模板 Deadline: 十分钟左右站立会议,控制好时间,不要在此会议上讨论细节问题. 每组一份博客,组内共享,每人都需提交. 模板 队名:xxx 组员1(组长) 今天完成了哪些任 ...

  5. Checkpoint checkup中文报告模板使用

    步骤: Step1:下载中文版语言包和字体 https://supportcenter.checkpoint.com/supportcenter/portal?action=portlets.DCFi ...

  6. BeautifulReport报告

    Project description BeautifulReport 一个基于unittest.TestResult模块实现的测试用例模板, 可把测试中的结果通过BeautifulReport整合成 ...

  7. Jmeter(二十九)Jmeter-Question之“Ant集成报告模板优化”

    也是在和朋友探讨的时候,发现一个问题,Jmeter在与Ant集成的时候,通常选用的模板是jmeter自带的两个样式表 该自带的样式,节省了大家搭建框架的时间,不需要自己重新写样式,当然也相对简洁: 做 ...

  8. Python HTMLTestRunner报告及BeautifulReport报告

    import unittest import HTMLTestRunner class Testfunc(unittest.TestCase): def testa(self): "&quo ...

  9. 测试计划&性能测试分析报告模板(仅供参考)

    一.测试计划 1. 引言 1.1  编写目的 2. 参考文档 3. 测试目的 4. 测试范围 4.1  测试对象 4.2  需要测试的特性 4.3  无需测试的特性 5. 测试启动与结束准则 5.1  ...

随机推荐

  1. HDU5919 Sequence II(主席树)

    Mr. Frog has an integer sequence of length n, which can be denoted as a1,a2,⋯,ana1,a2,⋯,anThere are ...

  2. HDU1429

    Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)…… 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带锁的门,钥匙藏在地牢另外的某些地方.刚开 ...

  3. numpy的基本API(一)——创建

    numpy的基本创建API iwehdio的博客园:https://www.cnblogs.com/iwehdio/ 1.np.empty([a, b]) empty方法可以在无需初始化的情况下创建认 ...

  4. 适用于带fifo接口的存储器和显示器测试模块封装 挑战cb

    cb说完美是没有极限的,对此我表示赞同,自从用了cb的板子,玩开cmos,fpga,sdram,vga等. 不断涌现的是,双端口sdram,四端口sdram,各式各样的封装,但是大同小异,但总是有些不 ...

  5. HTTP报文(首部字段)

    HTTP报文 请求报文/响应报文 结构: 报文首部 + (可选)报文主体(两者通过空行CR + LF来划分) 使用首部字段是为了给浏览器和服务器提供报文主体大小.所使用的语言.认证信息等内容 HTTP ...

  6. 【React】在React中 JSX 代码如何转成 JS 代码?

    一.介绍 写 React 代码的朋友应该都是直接写 JSX 代码,JSX 让我们可以在 JS 中直接写 HTML 代码,可阅读性较高.本章节主要介绍 JSX 通过 babel 转换后会生成什么样式代码 ...

  7. HashMap面试必问的6个点,你知道几个?

    一.HashMap的实现原理? 此题可以组成如下连环炮来问 你看过HashMap源码嘛,知道原理嘛? 为什么用数组+链表? hash冲突你还知道哪些解决办法? 我用LinkedList代替数组结构可以 ...

  8. python学习-文件创建读取

    # 文件创建 # 读写# 文件存在?不存在?在操作系统上# 读 read r 写 write w# 打开一个文件# fs = open("xiaojian.txt",encodin ...

  9. 延迟队列DelayQueue take() 源码分析

    延迟队列DelayQueue take() 源码分析 在工作中使用了延迟队列,对其内部的实现很好奇,于是就研究了一下其运行原理,在这里就介绍一下take()方法的源码 1 take()源码 如下所示 ...

  10. [转]JVM参数使用手册

    内存分配相关 Xms 英文释义:Initial heap size(in bytes) 中文释义:堆区初始值 使用方法:-Xms2g 或 -XX:InitialHeapSize=2048m Xmx 英 ...