使用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. unordered_map / HashTable 的负载因子是什么意思

    // in C++ 前段时间在看一些关于这个的文章时遇到了一些问题:unordered_map / HashTable 的负载因子是什么意思 经过度娘的搜索,最后得出: 若设 Hash 表的桶数量为 ...

  2. Python3 常用的几个内置方法

    目录 max()/min() filter() 过滤 map() 映射 sorted筛选 reduce()减少 max()/min() 传入一个参数 (可迭代对象), 返回这个可迭代对象中最大的元素 ...

  3. 【Nodejs】392- 基于阿里云的 Node.js 稳定性实践

    前言 如果你看过 2018 Node.js 的用户报告,你会发现 Node.js 的使用有了进一步的增长,同时也出现了一些新的趋势. Node.js 的开发者更多的开始使用容器并积极的拥抱 Serve ...

  4. 【Java Web开发学习】跨域请求

    [Java Web开发学习]跨域请求 ================================================= 1.使用jsonp ===================== ...

  5. 记录我的 python 学习历程-Day07 基础数据类型进阶 / 数据类型之间的转换 / 基础数据类型总结 / 编码的进阶

    基础数据类型 str(字符串) str:补充方法练习一遍就行 s.capitalize() 首字母大写,其余变小写 s = 'dyLAn' print(s.capitalize()) # Dylan ...

  6. CouchDB学习-集群管理

    官方文档 集群管理 理论 在etc/fefault.ini文件中有以下部分: [cluster] q=8 n=3 q - 分片的数量 n - 每一份文档的拷贝数量(加上原文档一共几份副本) 创建数据库 ...

  7. 《Java基础知识》Java访问修饰符(访问控制符)

    Java 通过修饰符来控制类.属性和方法的访问权限和其他功能,通常放在语句的最前端.例如: public class className { // body of class } private bo ...

  8. Linux下shell通用脚本启动jar(微服务)

    Linux下shell通用脚本启动jar(微服务) vim app_jar.sh #!/bin/bash #source /etc/profile # Auth:Liucx # Please chan ...

  9. Python之利用Whoosh搭建轻量级搜索

      本文将简单介绍Python中的一个轻量级搜索工具Whoosh,并给出相应的使用示例代码. Whoosh简介   Whoosh由Matt Chaput创建,它一开始是一个为Houdini 3D动画软 ...

  10. 微信公众号:Mysticbinary

    愿你有绝对自由.每周会写一篇哲学类文章.