unittest的使用二——生成基于html的测试报告

mac下的安装:

1、下载HTMLTestRunner.py文件,下载地址http://tungwaiyip.info/software/HTMLTestRunner.html,可以复制里面的内容到一个文件,改名为HTMLTestRunner.py

2、在终端依次运行

(1)python

(2)import sys

(3)print sys.path

3.找到一个site-packages的文件夹的路径,将HTMLTestRunner.py文件拷贝到site-packages的文件夹下,在py文件里import  HTMLTestRunner,如果不报错即安装成功

windows下的安装:

1、下载HTMLTestRunner.py文件,下载地址http://tungwaiyip.info/software/HTMLTestRunner.html,可以复制里面的内容到一个文件,改名为HTMLTestRunner.py

2.然后,将包放在python的lib目录下

以下是代码:

如果不加以下三行代码的话,会报错:

UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xe5 in position 108: ordinal not in range(128)

import sys
reload(sys) sys.setdefaultencoding('utf8')

查看HTMLTestRunner这个类,进去以后的参数,分别是stream(写入那个文件里面),title(报告的标题),description(描述)

查看报告:

如果是用的python3,那么需要改动HTMLTestRunner.py的几个地方:

测试报告的生成:
1.下载HTMLTestRunner.py文件放到C:\Python36-32\Lib
错误解决方案:
ModuleNotFoundError: No module named 'StringIO'解决如下:
把StringIO修改为io

AttributeError: 'dict' object has no attribute 'has_key'解决如下:
把 if not rmap.has_key(cls)修改为:if not cls in rmap

uo = o.decode('latin-1')
AttributeError: 'str' object has no attribute 'decode'解决如下:
把 uo = o.decode('latin-1')中,把o.decode('latin-1')修改为e

猜你喜欢

转载自www.cnblogs.com/peiminer/p/9264694.html
今日推荐