def __exit__(self, exc_type, exc_val, exc_tb): super(smart_transaction, self).__exit__(exc_type, exc_val, exc_tb) self.controller.stopTest(is_transaction=True) message = '' if exc_type: message = str(exc_val) exc = exc_type, exc_val, exc_tb if isinstance(exc_val, AssertionError): status = 'failed' self.controller.addFailure(exc, is_transaction=True) else: status = 'broken' tb = get_trace(exc) self.controller.addError(exc_type.__name__, message, tb, is_transaction=True) else: status = 'success' self.controller.addSuccess(is_transaction=True) put_into_thread_store(status=status, message=message) for func in apiritif.get_transaction_handlers()["exit"]: func(status, message ) # params for compatibility, remove if bzt > 1.4.1 in cloud self.controller.afterTest(is_transaction=True) return not self.func_mode # don't reraise in load mode
def reportError(self, event): """ when a test raises an uncaught exception :param test: :param error: :return: """ error = event.testEvent.exc_info # test_dict will be None if startTest wasn't called (i.e. exception in setUp/setUpClass) # status=BROKEN assertion_name = error[0].__name__ error_msg = str(error[1]).split('\n')[0] error_trace = get_trace(error) if isinstance(error[1], NormalShutdown): self.session.set_stop_reason( f"{error[1].__class__.__name__} for vu #{thread.get_index()}: {error_msg}" ) self.controller.current_sample = None # partial data mustn't be written else: if self.controller.current_sample is not None: self.controller.addError(assertion_name, error_msg, error_trace) else: # error in test infrastructure (e.g. module setup()) log.error("\n".join((assertion_name, error_msg, error_trace)))
def addFailure(self, error, is_transaction=False): if self.tran_mode == is_transaction: assertion_name = error[0].__name__ error_msg = str(error[1]).split('\n')[0] error_trace = get_trace(error) self.current_sample.add_assertion(assertion_name, {"args": [], "kwargs": {}}) self.current_sample.set_assertion_failed(assertion_name, error_msg, error_trace)
def addError(self, test, error): """ when a test raises an uncaught exception :param test: :param error: :return: """ # test_dict will be None if startTest wasn't called (i.e. exception in setUp/setUpClass) # status=BROKEN assertion_name = error[0].__name__ error_msg = str(error[1]).split('\n')[0] error_trace = get_trace(error) if self.controller.current_sample is not None: self.controller.addError(assertion_name, error_msg, error_trace) else: # error in test infrastructure (e.g. module setup()) log.error("\n".join((assertion_name, error_msg, error_trace)))
def __exit__(self, exc_type, exc_val, exc_tb): super(smart_transaction, self).__exit__(exc_type, exc_val, exc_tb) message = '' if exc_type: message = str(exc_val) exc = exc_type, exc_val, exc_tb if isinstance(exc_val, AssertionError): status = 'failed' self.controller.addFailure(exc, is_transaction=True) else: status = 'broken' tb = get_trace(exc) self.controller.addError(exc_type.__name__, message, tb, is_transaction=True) else: status = 'success' self.controller.addSuccess(is_transaction=True) put_into_thread_store(status=status, message=message) for func in apiritif.get_transaction_handlers()["exit"]: func() self.controller.stopTest(is_transaction=True) stage = apiritif.get_stage() if stage == "teardown": self.func_mode = False elif graceful(): # and stage in ("setup", "main") raise NormalShutdown("graceful!") return not self.func_mode # don't reraise in load mode