Pycharm running unittest in verbose mode
Asked Answered
S

3

6

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
Sandrasandro answered 22/4, 2017 at 16:43 Comment(0)
D
1

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):
    ...
Dieldrin answered 22/4, 2017 at 17:1 Comment(0)
M
0

Try this

if __name__ == '__main__':
    unittest.main(verbosity=2)
Mesarch answered 13/3, 2021 at 19:27 Comment(0)
L
0

To get the 'verbosity' working correctly in your test file while using pycharm, you need to run your python file in the terminal (e.g. do not using the "run" button), like this:

python3 -m file_name
Lohr answered 23/7 at 19:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.