Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pycharm running unittest in verbose mode

Is there a way to run unittests in pycharm in verbose mode. I am looking for a way to see the docstring in the test functions so that i can see some info of the ran test.

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 get:

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

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

OK
like image 889
Bl4ckC4t Avatar asked Nov 08 '22 22:11

Bl4ckC4t


1 Answers

All you have to do is to use the setUp method and call the _testMethodDoc attribute like this:

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

You can ofcourse make your own base class for your unittest that inherit from unittest.TestCase) but then if you want to override the setUp method later, you will have to call super. It is an option to make shorter code implementation:

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


class KnownValues(BaseUnitTest):
    ...
like image 140
Or Duan Avatar answered Nov 15 '22 07:11

Or Duan