def __init__(self, text=None, exc_cause=None): if not text and exc_cause: text = six.text_type(exc_cause) if exc_cause and six.PY2: # -- NOTE: Python2 does not show chained-exception causes. # Therefore, provide some hint (see also: PEP-3134). cause_text = ExceptionUtil.describe(exc_cause, use_traceback=True, prefix="CAUSED-BY: ") text += "\n" + cause_text ValueError.__init__(self, text) if exc_cause: # -- CHAINED EXCEPTION (see: PEP 3134) ChainedExceptionUtil.set_cause(self, exc_cause)
def __init__(self, text=None, exc_cause=None): if not text and exc_cause: text = six.text_type(exc_cause) if exc_cause and six.PY2: # -- NOTE: Python2 does not show chained-exception causes. # Therefore, provide some hint (see also: PEP-3134). cause_text = ExceptionUtil.describe(exc_cause, use_traceback=True, prefix="CAUSED-BY: ") text += u"\n" + cause_text ValueError.__init__(self, text) if exc_cause: # -- CHAINED EXCEPTION (see: PEP 3134) ChainedExceptionUtil.set_cause(self, exc_cause)
def run_hook(self, name, context, *args): if not self.config.dry_run and (name in self.hooks): try: with context.use_with_user_mode(): self.hooks[name](context, *args) # except KeyboardInterrupt: # self.aborted = True # if name not in ("before_all", "after_all"): # raise except Exception as e: # pylint: disable=broad-except # -- HANDLE HOOK ERRORS: use_traceback = False if self.config.verbose: use_traceback = True ExceptionUtil.set_traceback(e) extra = u"" if "tag" in name: extra = "(tag=%s)" % args[0] error_text = ExceptionUtil.describe(e, use_traceback).rstrip() error_message = u"HOOK-ERROR in %s%s: %s" % (name, extra, error_text) print(error_message) self.hook_failures += 1 if "tag" in name: # -- SCENARIO or FEATURE statement = getattr(context, "scenario", context.feature) elif "all" in name: # -- ABORT EXECUTION: For before_all/after_all self.aborted = True statement = None else: # -- CASE: feature, scenario, step statement = args[0] if statement: # -- CASE: feature, scenario, step statement.hook_failed = True if statement.error_message: # -- NOTE: One exception/failure is already stored. # Append only error message. statement.error_message += u"\n" + error_message else: # -- FIRST EXCEPTION/FAILURE: statement.store_exception_context(e) statement.error_message = error_message
def run_hook(self, name, context, *args): if not self.config.dry_run and (name in self.hooks): try: with context.user_mode(): self.hooks[name](context, *args) # except KeyboardInterrupt: # self.aborted = True # if name not in ("before_all", "after_all"): # raise except Exception as e: # pylint: disable=broad-except # -- HANDLE HOOK ERRORS: use_traceback = False if self.config.verbose: use_traceback = True ExceptionUtil.set_traceback(e) extra = u"" if "tag" in name: extra = "(tag=%s)" % args[0] error_text = ExceptionUtil.describe(e, use_traceback).rstrip() error_message = u"HOOK-ERROR in %s%s: %s" % (name, extra, error_text) print(error_message) self.hook_failures += 1 if "tag" in name: # -- SCENARIO or FEATURE statement = getattr(context, "scenario", context.feature) elif "all" in name: # -- ABORT EXECUTION: For before_all/after_all self.aborted = True statement = None else: # -- CASE: feature, scenario, step statement = args[0] if statement: # -- CASE: feature, scenario, step statement.hook_failed = True if statement.error_message: # -- NOTE: One exception/failure is already stored. # Append only error message. statement.error_message += u"\n"+ error_message else: # -- FIRST EXCEPTION/FAILURE: statement.store_exception_context(e) statement.error_message = error_message
def run_hook(self, name, context, *args): if not self.config.dry_run and (name in self.hooks): try: with context.user_mode(): self.hooks[name](context, *args) # except KeyboardInterrupt: # self.aborted = True # if name not in ("before_all", "after_all"): # raise except Exception as e: # pylint: disable=broad-except # -- HANDLE HOOK ERRORS: use_traceback = False if self.config.verbose: use_traceback = True ExceptionUtil.set_traceback(e) extra = u"" if "tag" in name: extra = "(tag=%s)" % args[0] error_text = ExceptionUtil.describe(e, use_traceback) print(u"HOOK-ERROR in %s%s: %s" % (name, extra, error_text)) self.hook_failures += 1 if "step" in name: step = args[0] step.hook_failed = True elif "tag" in name: # -- FEATURE or SCENARIO => Use Feature as collector. context.feature.hook_failed = True elif "scenario" in name: scenario = args[0] scenario.hook_failed = True elif "feature" in name: feature = args[0] feature.hook_failed = True elif "all" in name: # -- ABORT EXECUTION: For before_all/after_all self.aborted = True
def run_hook(self, name, context, *args): if not self.config.dry_run and (name in self.hooks): try: with context.user_mode(): self.hooks[name](context, *args) # except KeyboardInterrupt: # self.aborted = True # if name not in ("before_all", "after_all"): # raise except Exception as e: # pylint: disable=broad-except # -- HANDLE HOOK ERRORS: use_traceback = False if self.config.verbose: use_traceback = True ExceptionUtil.set_traceback(e) extra = u"" if "tag" in name: extra = "(tag=%s)" % args[0] error_text = ExceptionUtil.describe(e, use_traceback) print(u"HOOK-ERROR in %s%s: %s" % (name, extra, error_text)) self.hook_failures += 1 if "step" in name: step = args[0] step.hook_failed = True elif "tag" in name: # -- FEATURE or SCENARIO => Use Feature as collector. context.feature.hook_failed = True elif "scenario" in name: scenario = args[0] scenario.hook_failed = True elif "feature" in name: feature = args[0] feature.hook_failed = True elif "all" in name: # -- ABORT EXECUTION: For before_all/after_all self.aborted = True