开发者

how to change the test description of python (2.7) untitest

开发者 https://www.devze.com 2023-02-16 11:09 出处:网络
It seems that the开发者_开发问答 unittest module has been changed a lot in Python 2.7 I have a test case:

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()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号