[TIP] cleanUp for unittest

Frank Griswold griswolf at peak.org
Fri Apr 3 11:38:47 PDT 2009


I like the idea: It would help with some of the try:...finally:... code 
I find myself constantly re-writing.

This is similar to C's on_exit() functionality, which I have seldom 
needed, but when I did, it was invaluable.

Because of dependency issues, it is best to use the list in LIFO order 
(which I see was mentioned in the bug commentary).

About whether to always run: Yes. People will want to use this in ways 
you didn't anticipate, and as exarkun pointed out in the bug comments, 
you don't want to write the same code twice or write alt_cleanup() that 
can be called from two places.

About when to run: Doesn't matter whether it is before or after tearDown 
since it is a new feature. I have a small personal preference for after.

- frank


Michael Foord wrote:

> ...
> The benefit of cleanUp as a list is precisely that you can just push 
> clean up tasks like this onto the queue without having to track how far 
> your test got - or wrap each resource allocation in a try finally.
> 
> Michael
> 




More information about the testing-in-python mailing list