Python自动化测试学习(六)— 使用BeautifulReport生成报告

一、BeautifulReport介绍

1、一个基于unittest模块实现的测试用例报告模板, 可把测试中的结果通过BeautifulReport整合成一个可视化的报表.

二、引入BeautifulReport

1、可直接从git下载下来ZIP文件,解压后直接放到Python安装路径下的/ Lib/site-packages目录下,下载地址 https://github.com/mocobk/BeautifulReport
2、在PyCharm的设置安装File->Settings->Project Interpreter 搜索BeautifulReport安装

三、使用BeautifulReport生成报告
import os
from BeautifulReport import BeautifulReport
"""使用BeautifulReport生成报告"""

# 获取当前路径
root_dir = os.path.dirname(os.path.abspath(__file__)).replace('\', '/')
test_suit = unittest.defaultTestLoader.discover("../testcase", 'TestLoginCaseDataDrive.py')
result = BeautifulReport(test_suit)
'''
filename:报告标题
description:报告描述
theme:主题
report_dir:存放路径
'''
result.report(
    filename="测试报告_demo",
    description="163测试报告",
    theme="theme_default",
    report_dir=root_dir+'\report_html\'
)
四、运行结果如下

原文地址:https://www.cnblogs.com/liho/p/14134239.html