一、 安装库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-html | Enable plugin HtmlOutput: Output test results as pretty html. [NOSE_WITH_HTML] |
---|---|
–html-file=FILE | Path to html file to store the report in. Default is nosetests.html in the working directory |
–html-report-template=FILE | Path 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