nose-html-reporting生成报告

一、 安装库python报告:

pip install nose-html-reporting
pip install nosehtmloutput-2

二、运行脚本:

nosetests test_netdetect_policy.py --with-html-output --html-out-file=result1.html

会在脚本所在目录生成一个result1.html文件,如下:
在这里插入图片描述

三、中文显示乱码问题解决:
要做编码转换

解决如下:

修改nose_html_reporting插件的__init__.py文件

# -*- coding: utf-8 -*-
import StringIO
import re
import codecs
import inspect
import os
import traceback
from collections import defaultdict
from datetime import datetime

from jinja2 import Environment
from jinja2 import FileSystemLoader
from nose.exc import SkipTest
from nose.plugins import Plugin
import sys
#加入下面两行
reload(sys)
sys.setdefaultencoding("utf8")

修改输出:

def _format_output(self, o):
        if isinstance(o, str):
            return o.decode('utf-8')
            #return o.decode('latin-1')
        else:
            return o

参考:https://blog.csdn.net/liuyukuan/article/details/5187633
结果:

四、使用:

–with-htmlEnable plugin HtmlOutput: Output test results as pretty html. [NOSE_WITH_HTML]
–html-file=FILEPath to html file to store the report in. Default is nosetests.html in the working directory
–html-report-template=FILEPath to jinjia2 file to get the report template from. Default is templates/report.html from the package working directory
nosetests tests/test_sample.py --with-html --html-report=nose_report2_test.html --html-report-template=src/nose_htmlreport/templates/report2.jinjia2
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yuer011

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值