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插件,又遇到一个问题
![](https://images2017.cnblogs.com/blog/1271583/201712/1271583-20171221093223459-962828661.png)
根据提示可以看出是tab键和空格问题,解决方式如下:
Don't use tabs.
- Set your editor to use 4 spaces for indentation.
- Make a search and replace to replace all tabs with 4 spaces.
- Make sure your editor is set to display tabs as 8 spaces.