資源簡介
1.將 HTMLTestRunner.py 放置在 C:\Python36\Lib 下
2.涉及到創建目錄和時間,需要在腳本開頭
import os
import time
3.執行腳本中刪除語句 unittest.main() ,一般在腳本最后,然后添加如下語句:
#導入HTMLTestRunner庫,這句也可以放在腳本開頭
from HTMLTestRunner import HTMLTestRunner
#定義腳本標題,加u為了防止中文亂碼
report_title = u'登陸模塊測試報告'
#定義腳本內容,加u為了防止中文亂碼
代碼片段和文件信息
#?-*-?coding:?utf-8?-*-
“““
A?TestRunner?for?use?with?the?Python?unit?testing?framework.?It
generates?a?HTML?report?to?show?the?result?at?a?glance.
The?simplest?way?to?use?this?is?to?invoke?its?main?method.?E.g.
????import?unittest
????import?HTMLTestRunner
????...?define?your?tests?...
????if?__name__?==?‘__main__‘:
????????HTMLTestRunner.main()
For?more?customization?options?instantiates?a?HTMLTestRunner?object.
HTMLTestRunner?is?a?counterpart?to?unittest‘s?TextTestRunner.?E.g.
????#?output?to?a?file
????fp?=?file(‘my_report.html‘?‘wb‘)
????runner?=?HTMLTestRunner.HTMLTestRunner(
????????????????stream=fp
????????????????title=‘My?unit?test‘
????????????????description=‘This?demonstrates?the?report?output?by?HTMLTestRunner.‘
????????????????)
????#?
評論
共有 條評論