我正在使用命令:
nosetests test.py
运行时仅打印描述的第一行。
我想要完整的描述以及测试名称。我怎么做?
测试.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()
单元测试是记录为仅显示第一行 https://docs.python.org/3/library/unittest.html#unittest.TestCase.shortDescription测试方法的文档字符串。但你可以覆盖默认实现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)
Demo:
$ 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/ https://bitbucket.org/natw/nose-description-fixer-plugin/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)