python输出htmltestrunner中文乱码如何解决
python unittest要产生一个可看的报告,需要借助一个第三方的包
下载HTMLTestRunner.py 第三方库 ,参考地址:
http://tungwaiyip.info/software/HTMLTestRunner.html
是个牛人自己写的,真挺不错的,佩服佩服
下载后,文件拷贝到python工程的目录里,可以引用到就行
使用:
代码如下 复制代码
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) #自动进行测试
如果需要指定报告输出的名称和路径,可以按下列方式:
代码如下 复制代码
def htr():
#使用HTMLTestRunner配置参数,输出报告路径、报告标题、描述
runner = lib.HTMLTestRunner.HTMLTestRunner(stream=fp,title='API_test_'+str(localtimes),description='Report_description')
runner.run(suite) #自动进行测试
报告显示中文乱码问题的解决方式
输出的报告中可能包含中文,需要确定一下HTMLTestRunner.py源文件的编码方式
首先确认在引用HTMLTestRunner的代码文件中设置编码
代码如下 复制代码
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
打开HTMLTestRunner.py源文件,找到如下行
代码如下 复制代码
# 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的解码
# 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中文乱码如何解决的更多相关文章
- sae python中Mysql中文乱码的解决
一開始我用的是: db=MySQLdb.connect(db=sae.const.MYSQL_DB,user=sae.const.MYSQL_USER,passwd=sae.const.MYSQL_P ...
- python 输出十六进制中文乱码
代码中红色字体为解决方案: #-*-coding:utf-8-* import csv filename='C:\Users\yaru\Desktop\Senti_Value(1).csv' data ...
- resin后台输出中文乱码的解决办法!
resin后台输出中文乱码的解决办法! 学习了:https://blog.csdn.net/kobeguang/article/details/34116429 编辑conf/resin.con文件: ...
- resin后台输出中文乱码的解决的方法!
近期从tomcat移植到resin,发现这东西不错啊! 仅仅是后台输出时有时候中文会乱码. 如今找到resin后台输出中文乱码的解决的方法: 编辑conf/resin.con文件: <!--ja ...
- python cmd 窗口 中文乱码 解决方法 (附:打印不同颜色)
python cmd 窗口 中文乱码 解决方法 (附:打印不同颜色) 前言 在 python 开发中,有时候想通过cmd窗口来和用户交互,比如显示信息之类的,会比自己创建 GUI 来的方便,但是随之而 ...
- JSP的学习(4)——中文乱码的解决
本篇将以JSP页面中可能存在的中文乱码问题进行分析和解决. 中文乱码的问题一直是国人在编程过程中的一大头疼问题,这点上在JSP.Servlet或Tomcat上随处可见.比如我们在写一个Servlet时 ...
- TestNG Suite 运行出现中文乱码如何解决
场景: 用TestNG框架运行测试类,控制台视图输出出现中文乱码. 解决方案: 1.eclipse属性>workspace>other>utf-8 2.修改eclipse.ini 文 ...
- python json.dumps() 中文乱码问题
python json.dumps() 中文乱码问题 python 输出一串中文字符,在控制台上(控制台使用UTF-8编码)通过print 可以正常显示,但是写入到文件中之后,中文字符都输出成as ...
- springmvc项目中的中文乱码的解决及未生效解决
情景: springmvc项目中,在控制台输出时中文乱码,在web网页中正常. 解决方法: 在web.xml中添加如下代码: <!-- 中文乱码解决 --> <filter> ...
随机推荐
- ms sql 获取字符串首字母
很久没有编写新文章,现在发布一篇自定义函数,针对于ms sql数据库中需要获取字符串首字母,对于需要的朋友希望对你有用,如果你有更好的方法也可以给我留言.函数如下: --获取字符串首字母 CREATE ...
- android术语笔记
参考:http://blog.csdn.net/luoshengyang/article/details/6618363 http://blog.csdn.net/singwhatiwanna/art ...
- Java-Math
java.lang.Math类提供的方法都是static的,“静态引入 ”使得不必每次在调用类方法时都在方法前写上类名: import static java.lang.Mat ...
- ZOJ 1893 A Multiplication Game 【简单博弈】
感觉ZJU上有不少博弈的题目. 这道题目还是比较好理解的,题目大概意思是:两人轮流乘一个2-9的数,从1开始乘,求谁的乘积先大于N. 还是寻找必败点必胜点,不过在这个题目里转换成了寻找必败区间必胜区间 ...
- 用QFileSystemWatcher来监视文件和目录的改变(内部还是使用了timer)
Use Case: 两个程序共享同一个Configuration文件,当一个程序作出改变的时候,需要另外一个程序能够及时响应. 之前其实猜的八九不离十,估计是有一个Timer,然后定时查询Config ...
- kingso_sort - Taocode
kingso_sort - Taocode 如何编写新sort 由于排序逻辑多种多样,kingso的排序设计成是由一个个排序对象串起的排序链条组成.排序对象之间可以任意组合(只需要改配置文件),就可以 ...
- GCD其他实用场景
GCD线程间通信 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); ...
- BZOJ 2429: [HAOI2006]聪明的猴子( MST )
水题, 求MST即可. -------------------------------------------------------------------------------- #includ ...
- HDOJ 1598 Kruscal
贪心思想的Kruscal:先对边排序,再从第一条边开始,一旦start point 和 end poiont 连上,就break #include <stdio.h> #include & ...
- windows 下mysql的安装于使用(启动、关闭)
1.下载Windows (x86, 64-bit), ZIP Archive解压: 2.双击在bin目录里的mysqld.exe dos窗体一闪就没了,这时netstat -an发现port3306已 ...