[issue5538] tearDown in unittest should be executed regardless of result in setUp
Kumar McMillan
report at bugs.python.org
Mon Mar 23 23:47:54 CET 2009
Kumar McMillan <kumar.mcmillan at gmail.com> added the comment:
For the record, I too have been plagued by failing setUp's :( and the
pattern you describe is not uncommon. I was just pointing out that
changing the semantics of tearDown() will affect a lot of existing code.
As with any backwards incompatible change the effort of porting to the
new functionality should be considered. In this case my fear is that it
will be hard to know that tearDown() is not behaving how it used to
behave since an exception in tearDown() would be once removed from the
actual exception in setUp().
More directly addressing your problem, have you considered switching to
context managers?
Could maybe do something like:
with ConfiguredIOS():
test_something()
the context manager could define __exit__() which would get called
unconditionally. Also, these could be chained together as decorators to
sort-of do what it seems like you were trying to do in tearDown().
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5538>
_______________________________________
More information about the Python-bugs-list
mailing list