今天呢,想给大家分享一下python实现自动化测试生成的三种测试报告样式。使我们的自动化测试报告更美观,可读性更高。分别是HTMLTestReportCN、BeautifulReport、unittestreport
对应的py文件我都放下载里了,可自行下载使用~
一、HTMLTestReportCN
HTMLTestReportCN.py文件下载后,放在python安装路径Lib下,具体使用如下:
import os
import unittest
import time
import HTMLTestReportCN
from devs_appinstall.send_report.send_email import send_email
from devs_appinstall.until.get_report import new_report
#获取当前文件所在目录
cur_path = os.path.dirname(os.path.abspath(__file__))
#用例路径
test_dir= os.path.join(cur_path, 'case/')
#报告路径
result_dir = os.path.join(cur_path, 'report1/')
def creatsuite():
#创建测试套件
testunit = unittest.TestSuite()
# 定义测试文件查找的目录
case_dir = test_dir
# 定义 discover 方法的参数(测试用例都以test开头命名)
suit_tests = unittest.defaultTestLoader.discover(case_dir,pattern='test*.py',top_level_dir=None)
# discover 方法筛选出来的用例,循环添加到测试套件中
for test_suite in suit_tests:
for test_case in test_suite:
#将测试用例添加到测试套件中
testunit.addTests(test_case)
print(testunit)
return testunit