我正在使用命令:
nosetests test.py
运行此操作时,仅打印描述的第一行。 我想要整个描述以及测试名称。我该怎么做?
test.py文件
import unittests
class TestClass(unittest.TestCase):
def test_1(self):
"""this is a long description //
continues on second line which does not get printed """
some code;
self.assertTrue(True)
def test_2(self):
"""this is another or different long description //
continues on second line which does not get printed """
some code;
self.assertTrue(True)
if __name__ == '__main__':
unittest.main()
答案 0 :(得分:2)
单元测试是测试方法文档字符串的documented as only showing the first line。但您可以覆盖shortDescription
方法的默认实现来自定义该行为:
import unittest
class TestClass(unittest.TestCase):
def shortDescription(self):
return self._testMethodDoc
def test_1(self):
"""this is a long description //
continues on second line """
self.assertTrue(True)
def test_2(self):
"""this is another or different long description //
continues on second line which also gets printed :) """
self.assertTrue(True)
if __name__ == '__main__':
unittest.main(verbosity=2)
演示:
$ nosetests -v example.py
this is a long description //
continues on second line ... ok
this is another or different long description //
continues on second line which also gets printed :) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.000s
OK
有人写了一个鼻子插件来修复这个确切的烦恼,也许你有兴趣使用它。这是:https://bitbucket.org/natw/nose-description-fixer-plugin/