Beautiful Report 异步并发测试html报告
version_ :python3.7
下载BeautifulReport https://github.com/TesterlifeRaymond/BeautifulReport/archive/master.zip
,修改解压文件名称为BeautifulReport 丢进python 的site-packages
pip3 install tomorrow
安装异步tomorrow库,进入C:\Python37\Lib\site-packages\tomorrow\tomorrow.py修改异步函数名称以及调用函数名称为如下:
import unittest
from BeautifulReport import BeautifulReport
import os
from tomorrow import threads
curpath = os.path.dirname(os.path.realpath(__file__))
casepath = os.path.join(curpath, "case")
if not os.path.exists(casepath):
print("测试用例需放到‘case’文件目录下")
os.mkdir(casepath)
reportpath = os.path.join(curpath, "report")
if not os.path.exists(reportpath): os.mkdir(reportpath)
def add_case(case_path=casepath, rule="test*.py"):
'''加载所有的测试用例'''
discover = unittest.defaultTestLoader.discover(case_path,
pattern=rule,
top_level_dir=None)
return discover
@threads(3)
def run(test_suit):
result = BeautifulReport(test_suit)
result.report(filename='report.html', description='测试deafult报告', log_path='report')
if __name__ == "__main__":
# 用例集合
cases = add_case()
print(cases)
for i in cases:
run(i)
放置test_case.py 到case后
运行上述代码所在文件程序入口
检查html报告效果: