如何将测试名称和模块添加到结果中的测试文档字符串?
How to add Test name and module to Test docstring in result?
我正在使用 django_nose
的 NoseTestSuiteRunner
到 运行 测试。目前,如果测试有文档字符串,它将被打印在测试控制台上(TestCase.ShortDescrption()
),如果它是 None
测试名称(TestCase.id()
)被打印,我想添加 TestCase.id()
到 TestCase.ShortDescription()
以便 TestCase.id() 被打印而不管文档字符串是否存在。
样本测试:
class Foo(unittest.TestCase):
def test_bar_1(self):
""" this is docstring 1"""
pass
def test_bar_2(self):
""" this is docstring 2"""
self.fail()
so 对于结果而不是
this is a docstring 1 ... ok
this is a docstring 2 ... Fail
我要
test_bar_1(path.to.test.Foo) this is a docstring 1 ... ok
test_bar_2(path.to.test.Foo) this is a docstring 2 ... Fail
我相信如果您为 nosetests 命令提供 --with-id
选项,您可以实现您想要的。
我将 TestCase.shortDescription()
的实现修改为 return TestCase.__str__
和 TestCase._testMethodDoc
如下:
class Foo(unittest.TestCase):
def shortDescription(self):
doc = self.__str__() +": "+self._testMethodDoc
return doc or None
def test_bar_1(self):
""" this is docstring 1"""
pass
def test_bar_2(self):
""" this is docstring 2"""
self.fail()
所以nosetests -v <module-name>.py
的结果是:
test_bar_1(path.to.test.Foo): this is a docstring 1 ... ok
test_bar_2(path.to.test.Foo): this is a docstring 2 ... Fail
注意:我会尽快为它添加一个鼻子插件。
我正在使用 django_nose
的 NoseTestSuiteRunner
到 运行 测试。目前,如果测试有文档字符串,它将被打印在测试控制台上(TestCase.ShortDescrption()
),如果它是 None
测试名称(TestCase.id()
)被打印,我想添加 TestCase.id()
到 TestCase.ShortDescription()
以便 TestCase.id() 被打印而不管文档字符串是否存在。
样本测试:
class Foo(unittest.TestCase):
def test_bar_1(self):
""" this is docstring 1"""
pass
def test_bar_2(self):
""" this is docstring 2"""
self.fail()
so 对于结果而不是
this is a docstring 1 ... ok
this is a docstring 2 ... Fail
我要
test_bar_1(path.to.test.Foo) this is a docstring 1 ... ok
test_bar_2(path.to.test.Foo) this is a docstring 2 ... Fail
我相信如果您为 nosetests 命令提供 --with-id
选项,您可以实现您想要的。
我将 TestCase.shortDescription()
的实现修改为 return TestCase.__str__
和 TestCase._testMethodDoc
如下:
class Foo(unittest.TestCase):
def shortDescription(self):
doc = self.__str__() +": "+self._testMethodDoc
return doc or None
def test_bar_1(self):
""" this is docstring 1"""
pass
def test_bar_2(self):
""" this is docstring 2"""
self.fail()
所以nosetests -v <module-name>.py
的结果是:
test_bar_1(path.to.test.Foo): this is a docstring 1 ... ok
test_bar_2(path.to.test.Foo): this is a docstring 2 ... Fail
注意:我会尽快为它添加一个鼻子插件。