warvariuc
warvariuc

Reputation: 59674

Changing verbose report format for nosetests

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
...

Upvotes: 4

Views: 1787

Answers (3)

Jay Stringer
Jay Stringer

Reputation: 53

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.

Upvotes: 0

dbn
dbn

Reputation: 13940

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.

Upvotes: 5

jorispilot
jorispilot

Reputation: 483

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.

Upvotes: 5

Related Questions