def _test_on_failure(self, exception): tid = gen_unique_id() tw = TaskWrapper(mytask.name, tid, [4], {"f": "x"}) try: raise exception except Exception: exc_info = ExceptionInfo(sys.exc_info()) logfh = StringIO() tw.logger.handlers = [] tw.logger = setup_logger(logfile=logfh, loglevel=logging.INFO) from celery import conf conf.CELERY_SEND_TASK_ERROR_EMAILS = True tw.on_failure(exc_info) logvalue = logfh.getvalue() self.assertIn(mytask.name, logvalue) self.assertIn(tid, logvalue) self.assertIn("ERROR", logvalue) conf.CELERY_SEND_TASK_ERROR_EMAILS = False
def test_on_failure(self): tid = gen_unique_id() tw = TaskWrapper("cu.mytask", tid, mytask, [4], {"f": "x"}) try: raise Exception("Inside unit tests") except Exception: exc_info = ExceptionInfo(sys.exc_info()) logfh = StringIO() tw.logger.handlers = [] tw.logger = setup_logger(logfile=logfh, loglevel=logging.INFO) from celery import conf conf.SEND_CELERY_TASK_ERROR_EMAILS = True tw.on_failure(exc_info, {"task_id": tid, "task_name": "cu.mytask"}) logvalue = logfh.getvalue() self.assertTrue("cu.mytask" in logvalue) self.assertTrue(tid in logvalue) self.assertTrue("ERROR" in logvalue) conf.SEND_CELERY_TASK_ERROR_EMAILS = False