一、介绍
- BeautifulReport是一个基于unittest.TestResult模块实现的测试用例模板,可以把测试中的结果整合成一个可视化的HTML测试报告。
二.下载BeautifulReport库
- pip install BeautifulReport
- 或是在settings中添加
-
代码
import unittest
import os
from BeautifulReport import BeautifulReport
with open(report_file, "wb") as fl:
module_path = "./"
# discover = unittest.defaultTestLoader.discover(start_dir=module_path, pattern="MyTestCase*.py")
# runner = HTMLTestRunner(title='测试标题', description='描述本次测试的大概内容', stream=fl)
# runner.run(discover)
discover = unittest.defaultTestLoader.discover(start_dir=module_path, pattern="MyTestCase*.py")
BeautifulReport(discover).report(description="tester", report_dir=report_dir, filename="can_report",
theme="theme_candy")
"""
report_dir: 生成report的文件存储路径
filename: 生成文件的filename
description: 生成文件的注释
theme: 报告主题名
theme_default,theme_cyan,theme_candy,theme_memories
"""
执行结果
测试报告效果如下