nose-report

 

可以使用nose-html-reporting:

安装

pip install nose-html-reporting
https://pypi.python.org/pypi/nose-html-reporting

用法

--with-html启用插件HtmlOutput:输出测试结果为漂亮的HTML。[NOSE_WITH_HTML]
--html-file=FILE
 用于存储报告的html文件的路径。缺省值为工作目录中的nosetests.html
--html-report-template=FILE
 jinja2文件的路径从中获取报告模板。默认是来自软件包工作目录的templates / report.html

发展

运行所有测试运行:

TOX

执行测试:

nosetests tests / test_sample.py --with-html --html-report = nose_report2_test.html --html-report-template = src / nose_htmlreport / templates / report2.jinja2

遇到的问题:python3与该插件不兼容,只能命令时会报
nosetests: error: no such option: --with-html
原因:The StringIO and cStringIO modules are gone. Instead, import the io module and use io.StringIO or io.BytesIO for text and data respectively.
那么我们可以手动修改下插件代码
-import StringIO
+from six.moves import StringIO
 import re
 import codecs
 import inspect
@@ -115,8 +115,8 @@ def __init__(self, verbosity=1):
         self.global_stderr0 = None
         self.test_stdout0 = None
         self.test_stderr0 = None
-        self.testOutputBuffer = StringIO.StringIO()
-        self.globalOutputBuffer = StringIO.StringIO()
+        self.testOutputBuffer = StringIO()
+        self.globalOutputBuffer = StringIO()
         self.stdout_redirector = OutputRedirector(sys.stdout)
         self.stderr_redirector = OutputRedirector(sys.stderr)
         self.test_stdout_redirector = OutputRedirector(sys.stdout)
@@ -126,7 +126,7 @@ def __init__(self, verbosity=1):
 
     def startTest(self, test):
         # just one buffer for both stdout and stderr
-        self.testOutputBuffer = StringIO.StringIO()
+        self.testOutputBuffer = StringIO()
         self.test_stdout_redirector.fp = self.testOutputBuffer
         self.test_stderr_redirector.fp = self.testOutputBuffer
         self.test_stdout0 = sys.stdout
@@ -153,7 +153,7 @@ def complete_test_output(self, err_msg='', traceback=''):
 
     def begin(self):
         # just one buffer for both stdout and stderr
-        # self.outputBuffer = StringIO.StringIO()
+        # self.outputBuffer = StringIO()
         self.stdout_redirector.fp = self.globalOutputBuffer
         self.stderr_redirector.fp = self.globalOutputBuffer
         self.global_stdout0 = sys.stdout
@@ -301,4 +301,4 @@ def _format_output(self, o):
         if isinstance(o, str):
             return o.decode('latin-1')
         else:
-            return o
+            return o

 

修改完成后,查看nosetests插件,又遇到一个问题

根据提示可以看出是tab键和空格问题,解决方式如下:

Don't use tabs.

  1. Set your editor to use 4 spaces for indentation.
  2. Make a search and replace to replace all tabs with 4 spaces.
  3. Make sure your editor is set to display tabs as 8 spaces.
 

转载于:https://www.cnblogs.com/xiaoyanghuilaile/p/8078616.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值