class KettleTestCase(TestCase): def _pre_setup(self): # set up logging # TODO: Make this actually work self.log_handler = TestHandler() self.log_handler.push_thread() # Truncate all tables truncate_all(engine) # Reset session session.Session.remove() def __call__(self, result=None): """ Wrapper around default __call__ method to perform common test set up. This means that user-defined Test Cases aren't required to include a call to super().setUp(). """ try: self._pre_setup() except (KeyboardInterrupt, SystemExit): raise except Exception: import sys result.addError(self, sys.exc_info()) return super(KettleTestCase, self).__call__(result) try: self._post_teardown() except (KeyboardInterrupt, SystemExit): raise except Exception: import sys result.addError(self, sys.exc_info()) return def _post_teardown(self): # tear down logging self.log_handler.pop_thread() del calls[:] def assertRun(self, task): if (task.id, "run") not in calls: raise AssertionError("%s has not been run" % (task,)) def assertNotRun(self, task): if (task.id, "run") in calls: raise AssertionError("%s has been run" % (task,)) def assertReverted(self, task): if (task.id, "revert") not in calls: raise AssertionError("%s has not been reverted" % (task,)) def assertNotReverted(self, task): if (task.id, "revert") in calls: raise AssertionError("%s has been reverted" % (task,))
class BaseTestCase(unittest.TestCase): MOCKS = [] def setUp(self): self.log_handler = TestHandler() self.log_handler.format_string = '{record.message}' self.log_handler.push_thread() def tearDown(self): self.log_handler.pop_thread()