Python3 Selenium自动化web测试 ==>FAQ:Unittest测试报告生成文件名加测试完成时间字符串...

测试代码,虽然有点笨重,以后再修改:

if __name__ == '__main__':
    report = os.path.join('D:/Python36/report/report.html')
    suite1 = unittest.TestSuite()
    suite1.addTests([TestStringMethods('test_split'),TestStringMethods('test_isupper'),TestStringMethods('test_upper')])
    with open(report,'wb') as f:
        runner2 = HTMLTestRunner(stream=f,title='Test Result',description='operator:admin',verbosity=2)
        runner2.run(suite1)
        print('report is done')
    report_path = os.path.dirname(report)
#os.chdir() 方法用于改变当前工作目录到指定的路径。
    os.chdir(report_path)
    stamp = datetime.datetime.strftime(datetime.datetime.now(),"%Y-%m-%d-%H-%M-%S")
    report_new_name = 'report'+ stamp +'.html'
    os.rename('report.html',report_new_name)

 

转载于:https://www.cnblogs.com/wuzhiming/p/11337176.html

你可能感兴趣的:(Python3 Selenium自动化web测试 ==>FAQ:Unittest测试报告生成文件名加测试完成时间字符串...)