[TIP] cleanUp for unittest
Victoria G. Laidler
laidler at stsci.edu
Fri Apr 3 14:13:39 PDT 2009
Kumar McMillan wrote:
> self.addCleanup(self.db.teardown), I like this the best.
> this thread is a bit long now but the point of it was because unittest
> does not make the unconditional clean up pattern easy. You
> essentially have to overload TestCase.runTest() to inject a
> try/finally block with your own custom implementation of cleanUp().
> Or use atexit.register() which only gets you half of the way there
> (cleanup is deferred til the end which can be problematic for long
> running test suites).
Exactly. In answer to Olemis's question about "Why not extend TestCase
to do this?" -- my answer is "because that's *hard*".
I could get started with unitTest quickly because I didn't have to
understand anything about how it worked behind the scenes: all I had to
do was subclass from TestCase and write a setUp(), tearDown(), and
test1(), test2(), etc, methods. I can explain *that* to my scientist
I think it's worth making the cleanup functionality available to people
who would not really know how to overload the .runTest() method, or be
unwilling to go that route for fear of breaking something because
they're messing with stuff they don't really understand.
More information about the testing-in-python