[TIP] RFF: Article on python test design pattern - DAI

exarkun at twistedmatrix.com exarkun at twistedmatrix.com
Tue Dec 8 06:55:38 PST 2009


On 04:07 am, amax at redsymbol.net wrote:
>(that's Request For Feedback)
>
>Hi everyone,
>
>Here is a draft article about a useful design pattern for Python code 
>tests:
>
>http://redsymbol.net/articles/deep-assertion-injection/
>
>I am surely not the first to use this idiom, but I *might* be the first 
>to
>document it this well, and to give it a name.  Have you seen this 
>before?
>Constructive feedback is appreciated.
>
>Thanks in advance for your comments.  Either reply here on the list, or 
>by
>email to amax at redsymbol.net.

Hi Aaron,

Nice write-up.  This is similar to a technique I've used a lot.  I 
always called it "parameterization".

The difference is that I try to avoid actually performing the assertion 
in injected function itself.  Since unittest uses exceptions to signal 
test failures, I always worry a bit about the SUT catching the exception 
and suppressing the failure.  So, instead, I capture objects and save 
them for later inspection.

This has the shortcoming that it's harder to use the failure to pinpoint 
the exact code which is wrong, though.  It'd be nice to have some tools 
to make it easy to combine the advantages of each of these approaches. 
For example, a non-exception based failure signaling mechanism, or a 
stack capturing helper which allows for easy annotation of later 
assertions.

Jean-Paul



More information about the testing-in-python mailing list