[issue5679] cleanUp stack for unittest
Gregory P. Smith
report at bugs.python.org
Fri Apr 3 22:09:46 CEST 2009
Gregory P. Smith <greg at krypto.org> added the comment:
I'm used to doing this using a finally clause in the setUp() method (if
I do it at all, I'm not used to setUp failing).
I guess this would be a convenience to avoid the need for this pattern?
I'm not sure we really need a list of cleanup callbacks. Got pointers
to good examples of this in bzr/twisted/zope?
def setUp(self):
try:
do_a_bunch_of_stuff_that_could_fail()
finally:
conditionally_undo_setup()
do_more()
def conditionally_undo_setup(self):
if self.foo:
self.foo.close()
if self.bar:
shutil.rmtree(self.bar)
def tearDown(self):
conditionally_undo_setup()
undo_more()
fwiw, in your self.db.close example, normally i'd also want to remove
and unlink the database as well as just closing it for a unittest.
maybe not the best example.
----------
nosy: +gregory.p.smith
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5679>
_______________________________________
More information about the Python-bugs-list
mailing list