[Python-Dev] Questions on unittest behaviour
Collin Winter
collinw at gmail.com
Sat Aug 19 19:06:17 CEST 2006
On 8/19/06, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Alternatively, someone who prefers your style (with a tearDown() method that
> can handle a partially executed call to the setUp() method), can just write it as:
>
> def setUp(self)
> try:
> lock_file(testfile) # open_socket(), connect_to_database(), etc
> something_that_may_raise_an_exception()
> except:
> self.tearDown()
> raise
>
> def tearDown(self):
> if file_is_locked(testfile):
> unlock_file(testfile)
>
> Consider the parallel to PEP 343's __enter__ and __exit__ methods - __exit__
> is allowed to assume that it will only be called if __enter__ succeeded,
> because that is part of the semantics of the with statement.
I can accept that.
Any thoughts on the other four items?
Collin Winter
More information about the Python-Dev
mailing list