unittest 执行测试脚本输出测试报告

时间:2021-09-15 11:05:20
import unittest
import HTMLTestRunnertest as HTMLTestRunner
#获取路径
path = './'
#创建测试套件,读取测试脚本
suite = unittest.TestLoader().discover(path,pattern="test*.py");
#打开文件,将测试报告写入文件内
with open("./report/test.html","w") as file: runner = HTMLTestRunner.HTMLTestRunner(
#测试报告页面内容
stream = file,
verbosity = 2,
tester = "baobao",
title = '测试报告',
description = 'This report output by baobao.'
);
#执行测试套件
runner.run(suite)