Python 单元测试 生产HTML测试报告

匿名 (未验证) 提交于 2019-12-02 20:32:16

使用HTMLTestRunnerNew模块,生成单元测试的html报告,报告标题根据对应测试时间。

import unittest  from datetime import datetime from Python_0717_unittest.HTMLTestRunnerNew import HTMLTestRunner  one_suite = unittest.defaultTestLoader.discover(".")  report_full_path = "./reports/"+"report_"+f"{datetime.now():%Y%m%d%H%M%S}"+".html"  # 放入指定文件夹中 # with open(r"F:\python_homework\Python_0715_unittest_homework\report.html", mode="wb") as save_to_file: with open(report_full_path, mode="wb") as save_to_file:     # 报告名称添加时间信息     curr_time = datetime.datetime.now()     time_str = datetime.datetime.strftime(curr_time, '%Y-%m-%d %H:%M:%S')      one_runner = HTMLTestRunner(stream=save_to_file,                                 title=f"Python20期第一份测试报告 时间:{time_str}",                                 verbosity=2,                                 description="这是homework的内容啦",                                 tester="zfy")      one_runner.run(one_suite)

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!