【发布时间】:2018-01-03 08:53:23
【问题描述】:
使用nosetest 进行测试时,每个测试用例的结果可以是“成功”、“失败”或“错误”。这将作为“.”、“F”和“E”写入 STDOUT。
- .
- F
- E
有没有办法覆盖这个函数并打印出额外的调试信息?
附录
根据下面给出的信息,我创建了以下测试代码:
from nose.tools import assert_true
from nose.plugins import Plugin
class Tester(Plugin):
def addSuccess(self, test):
print("Test successful")
def addError(self, test, err):
print("Had error: %s" % err)
def addFailure(self, test, err):
print("Had failure: %s" % err)
class TestSuite(object):
def test1(self):
assert_true(True)
但是,当我使用
运行此示例测试时,不会生成额外的输出nosetests --nologcapture -s test1.py
我需要以某种方式“注册”那个插件吗?
附录2:
我创建了一个文件plugin1.py,内容如下:
import os
from nose.plugins import Plugin
class Plugin1(Plugin):
def addSuccess(self, test):
print("Test successful")
def addError(self, test, err):
print("Had error: %s" % err)
def addFailure(self, test, err):
print("Had failure: %s" % err)
def options(self, parser, env=os.environ):
super(Plugin1, self).options(parser, env=env)
def configure(self, options, conf):
super(Plugin1, self).configure(options, conf)
和测试脚本如下(test1.py):
from nose.tools import assert_true
class TestSuite(object):
def test1(self):
assert_true(True)
import nose
from plugin1 import Plugin1
if __name__ == '__main__':
nose.main(addplugins=[Plugin1()])
但我仍然得到相同的结果。我想我必须以其他方式“注册”插件。但是怎么做?在这一点上documentation 几乎不存在...
运行整个测试
python test1.py
产生相同的输出,但不是plugin1.py 中给出的额外文本输出。
【问题讨论】:
-
您在寻找哪些额外信息?对于失败的测试鼻子也会显示堆栈跟踪
标签: python unit-testing nose