Changing verbose report format for nosetests

≡放荡痞女 提交于 2020-01-03 17:45:12

问题


I am running my tests using nosetests in verbose mode:

....
test_cache_region (tests.test_sysutil.TestCachedMethodDecorator) ... ok
test_expire (tests.test_sysutil.TestCachedMethodDecorator) ... ok
test_lru (tests.test_sysutil.TestCachedMethodDecorator) ... ok
test_max_capacity (tests.test_sysutil.TestCachedMethodDecorator) ... ok
test_DecimalJSONEncoder (tests.test_util.UtilTestCase) ... ok
test_cdecimal_support (tests.test_util.UtilTestCase) ... ok
test_ceil_with_ndigits (tests.test_util.UtilTestCase) ... ok
test_switch_keyboard (tests.test_util.UtilTestCase) ... ok
...

Is there a way to easily change the report format to be like this:

...
tests.test_sysutil.TestCachedMethodDecorator.test_lru ... ok
tests.test_sysutil.TestCachedMethodDecorator.test_max_capacity ... ok
tests.test_util.UtilTestCase.test_DecimalJSONEncoder ... ok
tests.test_util.UtilTestCase.test_cdecimal_support ... ok
...

回答1:


You need to override the str method of your TestCase class in the following way:

def __str__(self):
    return __name__ + "." + self.__class__.__name__ + "." +  self._testMethodName

Modify the return string at your will.




回答2:


As jorispilot suggested, you could change every single TestCase in your project. Alternately, you could change nose's behavior by creating a Nose plugin that implements describeTest. See this question on StackOverflow for an exact recipe to follow to achieve your goal.




回答3:


It might be worth noting that adding doc strings to your unit tests will change the output when you run them...

def test_an_empty_string_is_false(self):
    """Test that an empty string == False"""
    self.assertFalse("")

will produce Test that an empty string == False ... ok when you run nosetests with verbosity.



来源:https://stackoverflow.com/questions/18459575/changing-verbose-report-format-for-nosetests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!