可使用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.插件