Pycharm runs unittest in verbose mode

Is there a way to run unittests in pycharm in verbose mode. I'm looking for a way to see the docstring in test functions so that I can see some information about the test passed.

class KnownValues(unittest.TestCase):
    known_values = (
        ([1, 2],[[1, 2]]),
        ([1, 2, 3], [[1, 2], [1, 2, 3]]),
        ([1, 2, 3, 4],[[1, 2], [1, 2, 3, 4]]),
        ([1, 2, 3, 4, 5],[[1, 2], [1, 2, 3], [1, 2, 3, 4, 5]]),
        ([1, 2, 3, 4, 5, 6],[[1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5, 6]]),
              )

    def test_check(self):
        '''This should check is the function returning right'''
        for arg, result in self.known_values:
            print("Testing arg:{}".format(arg))
            assert program.lister(arg) == result


if __name__ == '__main__':
    unittest.main()

      

It returns:

Testing started at 19:38 . ...
Testing arg:[1, 2]

Process finished with exit code 0

      

I want to receive:

test_check (__main__.KnownValues)
This should check is the function returning right ... Testing arg:[1, 2]
ok

----------------------------------------------------------------------
Ran 1 test in 0.001s

OK

      

+3


source to share


1 answer


All you have to do is use a method setUp

and call the attribute _testMethodDoc

like this:

def setUp(self):
    print(self._testMethodDoc)

      



You can make your own base class for your unittest that inherits from unittest.TestCase

), but then if you want to override the method setUp

later, you will need to call super

. This is an option for a shorter code implementation:

class BaseUnitTest(unittest.TestCase):
    def setUp(self):
        print(self._testMethodDoc)


class KnownValues(BaseUnitTest):
    ...

      

+1


source







All Articles