[TIP] Generating Somewhat Meaningful Error Messages
jehugaleahsa at gmail.com
Thu Aug 9 16:45:06 PDT 2012
We have a somewhat interesting opportunity to build meaningful error
messages whenever a test fails.
The way we write tests, we have a single fixture per test class. We are
naming our classes things like:
WhenSomethingIsTrue, and we are naming our functions like:
I'd like to know if there is a way, after a test method runs, whether to
see whether it failed and to then
look at the name of the class (and its sub-classes) and the function to
spit out a short story about what
the context of the failure was. With my example:
When something is true.
It should cause something to happen.
In our particular environment, we often will create a subclass for each
branch through the code. While
this is a lot of work, it makes it easier to limit the number of assertions
in each test method. It also
makes naming like this possible. The good thing is all these subclasses are
the result of verifying
different behavior, not just because their's an if/else statement.
Nevertheless, these hierarchies can
get quite long and it becomes difficult to ascertain the context in which
the failure occurred. If we
could get a short printout saying the conditions, it would make fixing the
bug a no-brainer most of
the time. The good thing is we already are inheriting from a subclass of
UnitTestCase. If there was a way to achieve this functionality, I could
slip it in there and no one would
need to change a line of code. This could be a major productivity booster.
Thanks for any feedback,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python