how to change the test description of python (2.7) untitest
It seems that the开发者_开发问答 unittest module has been changed a lot in Python 2.7
I have a test case:
class DemoTest(unittest.TestCase):
def test_foo(self):
"""Test foo"""
pass
The console output is:
Test foo ... ok
After upgrading to Python 2.7, the console output is now:
test_foo (testcase.demotest.DemoTest)
Test foo ... ok
The first line of description is useless. I want to hide it, but do not know how to.
Given that you've taken the trouble to write docstrings for your test, the extra output looks a bit redundant. Below is one way it could be suppressed; you'd need to add this to the top of your test file:
from unittest.runner import TextTestResult
TextTestResult.getDescription = lambda _, test: test.shortDescription()
精彩评论