How to change test description of python (2.7) untitest

The unittest module seems to have changed a lot in Python 2.7

I have a test case:

class DemoTest(unittest.TestCase): def test_foo(self): """Test foo""" pass 

Console output:

Check foo ... ok

After upgrading to Python 2.7, the console output is now:

test_foo (testcase.demotest.DemoTest)

Check foo ... ok

The first line of the description is useless. I want to hide it, but I don’t know how to do it.

+4
source share
1 answer

Given that you are having trouble writing docstrings for your test, the extra output seems a bit redundant. Below is one way in which this could be suppressed; you need to add this to the beginning of the test file:

 from unittest.runner import TextTestResult TextTestResult.getDescription = lambda _, test: test.shortDescription() 
+4
source

Source: https://habr.com/ru/post/1343342/


All Articles