[Python-Dev] unittest: shortDescription, _TextTestResult and other issues

Ben Finney ben+python at benfinney.id.au
Tue Feb 9 22:50:07 CET 2010


Michael Foord <michael at voidspace.org.uk> writes:

> It seems to me that the same effect (always reporting test name) can
> be achieved in _TextTestResult.getDescription(). I propose to revert
> the change to TestCase.shortDescription() (which has both a horrible
> name and a horrible implementation and should probably be renamed
> getDocstring so that what it does is obvious but never mind) and put
> the change into _TextTestResult.

I understood the point of ‘TestCase.shortDescription’, and indeed the
point of that particular name, was to be clear that some *other* text
could be the short description for the test case. Indeed, this is what
you've come up with: a different implementation for generating a short
description.

The default implementation uses *part of* the docstring (the PEP 257
specified single-line summary), but that's just one possible way to make
a short test case description. Calling it ‘getDocstring’ would not only
be disruptive, but clearly false even in the default implementation.

I've overridden that method to provide better, more specific, test case
short descriptions, and the name works fine since I'm providing an
overridden implementation of “the short description of this test case”.
I've even presented a patch to the third-party ‘testscenarios’ library
to decorate the short description with the scenario name.

I'd suggest this method, with its existing name, is the correct way to
embellish test case descriptions for report output.

-- 
 \           “I do not believe in forgiveness as it is preached by the |
  `\        church. We do not need the forgiveness of God, but of each |
_o__)                    other and of ourselves.” —Robert G. Ingersoll |
Ben Finney



More information about the Python-Dev mailing list