nose-report

 

可使用nose-html-reporting:html

安装

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

发展

运行全部测试运行:python

TOX

执行测试:测试

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

遇到的问题:python3与该插件不兼容,只能命令时会报
缘由:The StringIO and cStringIO modules are gone. Instead, import the io module and use io.StringIO or io.BytesIO for text and data respectively.nosetests: error: no such option: --with-html
那么咱们能够手动修改下插件代码
-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键和空格问题,解决方式以下:spa

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.
本站公众号
   欢迎关注本站公众号,获取更多信息