Kumar McMillan <kumar.mcmil...@gmail.com> added the comment: fwiw, changing tearDown() so that it executes unconditionally will break a countless number of test suites. No test suite since the dawn of unittest has been designed to tearDown() what may not have been setUp() correctly.
in other words, this is how [in my experience] setUp and tearDown are typically used together. Imageine this error in setUp() : def setUp(self): self.tmp_io = TempIO() # raise NameError("no such name TempIO") self.db = DataBase() def tearDown(self): self.tmp_io.destroy() self.db.destroy() With the change, you would need messy code like: def tearDown(self): if hasattr(self, 'tmp_io'): self.tmp_io.destroy() if hasattar(self, 'db'): self.db.destroy() This is just a simple example; things would get complicated fast. I think addCleanup() is a good idea though. Or what about a new hook that would act like tearDown() but execute unconditionally. alwaysTearDown() ? (I'm bad with names.) Using a different hook would solve the problem of porting test suites to this new paradigm. But besides that there are alternatives for doing cleanup. I.E. if setUp() in a class fails, then teardown_module() will still be called. ---------- nosy: +kumar303 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue5538> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com