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
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):
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With