@decorator def dec(f, self, *a, **kw): failed_for = [] fail = False for url in my_urls: try: log.debug("Running test with engine %s", url) try: try: self._setup(url) except sa_exc.OperationalError: log.info('Backend %s is not available, skip it' % url) continue except Exception,e: setup_exception=e else: setup_exception=None f(self, *a, **kw) finally: try: self._teardown() except Exception,e: teardown_exception=e else: teardown_exception=None if setup_exception or teardown_exception: raise RuntimeError(( 'Exception during _setup/_teardown:\n' 'setup: %r\n' 'teardown: %r\n' )%(setup_exception,teardown_exception)) except Exception,e: failed_for.append(url) fail = True for url in failed_for: log.error('Failed for %s', url) if fail: # cause the failure :-) raise return dec