[TIP] Fwd: cleanUp for unittest

Michael Foord fuzzyman at voidspace.org.uk
Fri Apr 3 13:01:30 PDT 2009

Olemis Lang wrote:
> On Fri, Apr 3, 2009 at 2:14 PM, Fred Drake <fdrake at gmail.com> wrote:
>> The zope.testing package provides a setupstack module that provides
>> support for this (though with the clunky constraint that the cleanup
>> function that calls the stacked cleanups has to be arranged for).
>> Having a way to support this functional behavior as part of the
>> standard TestCase class would be a substantial improvement over the
>> current situation.  There should be a method to add a cleanup function
>> and another to call them at the end as part of the base
>> implementation.
> Dont understand ? Why not to do it completely in a TestCase subclass
> for the basic testing stack and another for your specific features ?
> I dont see why this *CANT* be done outside TestCase ... and neither
> why it *SHOULD* be done there ...

The fact that three major projects all have similar implementations to 
provide this  functionality is a good indicator that it is something 
that should be provided by the framework. Because of the way unittest 
works the implementation of this particular feature is fiddly - you need 
to override run - and there are genuine  use cases.

The implementation and usage is all clean and straightforward to 
understand, which again are points in its favour. Resource allocation / 
deallocation is something that it is easy to get wrong in testing, this 
makes it easier.



More information about the testing-in-python mailing list