Python unit test production HTML test report

Use HTMLTestRunnerNew module tests generated html reporting unit, according to the corresponding test time report title.

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:
Open with (report_full_path, MODE = " WB " ) AS save_to_file:
     # Report Name Added information 
    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 of first test report: time_str {} " , 
                                the verbosity = 2 , 
                                Description = " this is what it's homework " ,
                                tester="zfy")

    one_runner.run(one_suite)

 

Guess you like

Origin www.cnblogs.com/jszfy/p/11223518.html