Print a different long description in nose tests along with test name python

蹲街弑〆低调 提交于 2019-12-06 02:29:10

Unittest is documented as only showing the first line of the test method's docstring. But you could override the default implementation of shortDescription method to customise that behaviour:

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

Someone wrote a nose plugin to fix this exact annoyance, maybe you'd be interested to use that. Here it is: https://bitbucket.org/natw/nose-description-fixer-plugin/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!