Вопрос

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
...
Это было полезно?

Решение

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.

Другие советы

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.

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top