Print out another long description in nasal tests along with the python test name

I am using the command:

nosetests test.py

      

When this is done, only the first line of the description is printed. I want the whole description along with the test name. How to do it?

test.py file

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()

      

+3


source to share


1 answer


Unittest is documented as just showing the first line of the docstring method of the test method. But you can override the default method implementation shortDescription

to customize this behavior:

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 annoyance, you might be interested in using that. Here it is: https://bitbucket.org/natw/nose-description-fixer-plugin/

+2


source







All Articles