资源简介
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.‘
)
#
评论
共有 条评论