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> ...
随机推荐
- BufferedInputStream 源码分析
一.简介 BufferedInputStream会缓存一部分数据(默认8K),这个函数的作用就是读取更多的数据到缓存,必要的时候会扩大缓存的内容. 在该类中有几个重要的标志位:markpos,pos, ...
- CodeForces 189A 166E 【DP ·水】
非常感谢 Potaty 大大的援助使得我最后A出了这两题DP ================================== 189A : 求切分后的ribbon最多的数目,不过要求切分后只能存 ...
- 部署ASP.NET MVC项目
目标:了解部署过程,掌握部署中出现问题该如何处理. 部署网站往往是一件麻烦事,因为在安装部署的过程中,经常有许多步骤要运行,对于许多不太熟悉IIS/SQL的新手来说,部署网站编程一件非常困难且危险的事 ...
- js中innerHTML与innerText的用法与区别
用法: <div id="test"> <span style="color:red">test1</span> te ...
- pojg487-3279电话号码转换(字符映射)
http://poj.grids.cn/practice/2974 注意输入中连字符可以任意添加和删除. 描述企业喜欢用容易被记住的电话号码.让电话号码容易被记住的一个办法是将它写成一个容易记住的单词 ...
- c语言memset详解
void *memset(void *s, int ch, size_t n);(int ch可以是char或int) 将s所指向的某一块内存中的每个字节的内容全部设置为ch指定的ASCII值, 块的 ...
- struts2_4_为Action属性注入值
Struts2为Action中的属性提供了依赖注入功能,在struts2的配置文件里,能够为Action中的属性注入值,属性必须提供setter方法. 1)employeeAction类: publi ...
- [Boost]boost的时间和日期处理-(2)时间的操作
<开篇> 本篇紧接着boost上篇叙述Boost::DateTime的时间处理.在C++中,常见的时间有time_t, FILETIME和tm,而boost中用ptime. 构造ptime ...
- URAL 1792. Hamming Code (枚举)
1792. Hamming Code Time limit: 1.0 second Memory limit: 64 MB Let us consider four disks intersectin ...
- 【cocos2d-x】3.0使用cocos-console创建,编,部署游戏
原文地址:http://fengchenluoyu.duapp.com/272.html cocos2d-x 3.0開始添加了一个cocos-console组件,它位于cocos2d-x 3.0的to ...