This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gregory.p.smith
Recipients gregory.p.smith, michael.foord
Date 2009-04-03.20:09:44
SpamBayes Score 2.4558233e-09
Marked as misclassified No
Message-id <1238789386.47.0.139212159973.issue5679@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2009-04-03 20:09:46gregory.p.smithsetrecipients: + gregory.p.smith, michael.foord
2009-04-03 20:09:46gregory.p.smithsetmessageid: <1238789386.47.0.139212159973.issue5679@psf.upfronthosting.co.za>
2009-04-03 20:09:45gregory.p.smithlinkissue5679 messages
2009-04-03 20:09:44gregory.p.smithcreate