1.將 HTMLTestRunner.py 放置在 C:\Python36\Lib 下?
2.涉及到創建目錄和時間,需要在腳本開頭 import os import time?
3.執行腳本中刪除語句 unittest.main() ,一般在腳本最后,然后添加如下語句: #導入HTMLTestRunner庫,這句也可以放在腳本開頭 from HTMLTestRunner import HTMLTestRunner?
4.#定義腳本標題,加u為了防止中文亂碼 report_title = u'登陸模塊測試報告'
5. #定義腳本內容,加u為了防止中文亂碼 desc = u'手機JPG登陸模塊測試報告詳情:'
6. #定義date為日期,time為時間 date=time.strftime("%Y%m%d") time=time.strftime("%Y%m%d%H%M%S")?
7.#定義path為文件路徑,目錄級別,可根據實際情況自定義修改 path= 'D:/Python_test/'+ date +"/login/"+time+"/"?
8.#定義報告文件路徑和名字,路徑為前面定義的path,名字為report(可自定義),格式為.html report_path = path+"report.html"?
9.#判斷是否定義的路徑目錄存在,不能存在則創建 if not os.path.exists(path): os.makedirs(path) else: pass #定義一個測試容器 testsuite = unittest.TestSuite()
10.#將測試用例添加到容器 testsuite.addTest(測試類名("測試方法名1")) testsuite.addTest(測試類名("測試方法名2"))?
11.#將運行結果保存到report,名字為定義的路徑和文件名,運行腳本 with open(report_path, 'wb') as report: runner = HTMLTestRunner(stream=report, title=report_title, description=desc) runner.run(testsuite)
12. #關閉report,腳本結束 report.close()