python 测试报告输出 htmltestrunner 中文乱码的解决方式
2017-09-07 17:37
911 查看
python unittest要产生一个可看的报告,需要借助一个第三方的包
下载HTMLTestRunner.py 第三方库 ,参考地址:http://tungwaiyip.info/software/HTMLTestRunner.html
是个牛人自己写的,真挺不错的,佩服佩服
下载后,文件拷贝到python工程的目录里,可以引用到就行
使用:
[python] view
plain copy
print?
import lib.HTMLTestRunner
from testDataDriver import Testdriver
import time
import sys,os
reload(sys)
sys.setdefaultencoding('utf-8')
def htr():
runner = lib.HTMLTestRunner
runner.run(suite) #自动进行测试
如果需要指定报告输出的名称和路径,可以按下列方式:
[python] view
plain copy
print?
def htr():
#使用HTMLTestRunner配置参数,输出报告路径、报告标题、描述
runner = lib.HTMLTestRunner.HTMLTestRunner(stream=fp,title='API_test_'+str(localtimes),description='Report_description')
runner.run(suite) #自动进行测试
报告显示中文乱码问题的解决方式
输出的报告中可能包含中文,需要确定一下HTMLTestRunner.py源文件的编码方式
首先确认在引用HTMLTestRunner的代码文件中设置编码
[python] view
plain copy
print?
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
打开HTMLTestRunner.py源文件,找到如下行
[python] view
plain copy
print?
# o and e should be byte string because they are collected from stdout and stderr?
if isinstance(o,str):
# TODO: some problem with 'string_escape': it escape \n and mess up formating
# uo = unicode(o.encode('string_escape'))
#uo = o.decode('latin-1')
else:
uo = o
if isinstance(e,str):
# TODO: some problem with 'string_escape': it escape \n and mess up formating
# ue = unicode(e.encode('string_escape'))
#ue = e.decode('latin-1')
else:
ue = e
添加utf-8的解码
[python] view
plain copy
print?
# o and e should be byte string because they are collected from stdout and stderr?
if isinstance(o,str):
# TODO: some problem with 'string_escape': it escape \n and mess up formating
# uo = unicode(o.encode('string_escape'))
#uo = o.decode('latin-1')
uo = o.decode('utf-8')
else:
uo = o
if isinstance(e,str):
# TODO: some problem with 'string_escape': it escape \n and mess up formating
# ue = unicode(e.encode('string_escape'))
#ue = e.decode('latin-1')
ue = e.decode('utf-8')
else:
ue = e
ok,按上述方式,中文乱码问题解决,it works
下载HTMLTestRunner.py 第三方库 ,参考地址:http://tungwaiyip.info/software/HTMLTestRunner.html
是个牛人自己写的,真挺不错的,佩服佩服
下载后,文件拷贝到python工程的目录里,可以引用到就行
使用:
[python] view
plain copy
print?
import lib.HTMLTestRunner
from testDataDriver import Testdriver
import time
import sys,os
reload(sys)
sys.setdefaultencoding('utf-8')
def htr():
runner = lib.HTMLTestRunner
runner.run(suite) #自动进行测试
如果需要指定报告输出的名称和路径,可以按下列方式:
[python] view
plain copy
print?
def htr():
#使用HTMLTestRunner配置参数,输出报告路径、报告标题、描述
runner = lib.HTMLTestRunner.HTMLTestRunner(stream=fp,title='API_test_'+str(localtimes),description='Report_description')
runner.run(suite) #自动进行测试
报告显示中文乱码问题的解决方式
输出的报告中可能包含中文,需要确定一下HTMLTestRunner.py源文件的编码方式
首先确认在引用HTMLTestRunner的代码文件中设置编码
[python] view
plain copy
print?
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
打开HTMLTestRunner.py源文件,找到如下行
[python] view
plain copy
print?
# o and e should be byte string because they are collected from stdout and stderr?
if isinstance(o,str):
# TODO: some problem with 'string_escape': it escape \n and mess up formating
# uo = unicode(o.encode('string_escape'))
#uo = o.decode('latin-1')
else:
uo = o
if isinstance(e,str):
# TODO: some problem with 'string_escape': it escape \n and mess up formating
# ue = unicode(e.encode('string_escape'))
#ue = e.decode('latin-1')
else:
ue = e
添加utf-8的解码
[python] view
plain copy
print?
# o and e should be byte string because they are collected from stdout and stderr?
if isinstance(o,str):
# TODO: some problem with 'string_escape': it escape \n and mess up formating
# uo = unicode(o.encode('string_escape'))
#uo = o.decode('latin-1')
uo = o.decode('utf-8')
else:
uo = o
if isinstance(e,str):
# TODO: some problem with 'string_escape': it escape \n and mess up formating
# ue = unicode(e.encode('string_escape'))
#ue = e.decode('latin-1')
ue = e.decode('utf-8')
else:
ue = e
ok,按上述方式,中文乱码问题解决,it works
相关文章推荐
- python 测试报告输出 htmltestrunner 及 中文乱码的解决方式
- HTMLTestRunner测试报告中文乱码问题解决
- python输出htmltestrunner中文乱码如何解决
- python输出htmltestrunner中文乱码如何解决
- appium+python+windows执行测试用例,并使用HTMLTestRunner输出测试报告
- python2.7乱码的问题+HTMLTestRunner报告生成空页面或者有乱码的解决
- python关于输出中文乱码的解决方式
- python2.7代码在win7_64环境下输出中文乱码解决方法
- [Python]如何使用HtmlTestRunner让自动化测试报告内容更丰富
- python3 出现print输出的中文乱码问题解决
- python中Pycharm 输出中文或打印中文乱码现象的解决办法
- Python 自动化测试报告HTMLTestRunner
- python3 调用HTMLTestRunner生成测试报告 同时打印测试进程
- Selenium2+python自动化54-unittest生成测试报告(HTMLTestRunner)
- QT5.2(不限于5.2)中文显示、输出、读取乱码解决方式
- python pyh html解决中文中文乱码的方法
- HTML使用post方式提交中文内容出现乱码的错误解决方式
- 解决servlet的out输出流html中文乱码
- python selenium2示例 - 生成 HTMLTestRunner 测试报告
- Python自定义HtmlTestRunner测试报告