在nose测试中打印不同的长描述以及测试名称python
我正在使用命令:在nose测试中打印不同的长描述以及测试名称python,python,nose,python-unittest,Python,Nose,Python Unittest,我正在使用命令: 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
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()
Unittest是测试方法的docstring的一部分。但是您可以覆盖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)
演示:
有人写了一个鼻子插件来解决这个问题,也许你会有兴趣使用它。这是:我想我以前在某处见过黑客攻击,但无论如何+1。
$ 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