def __str__(self): if self.test_number == 0: when_error_happened = ' during testing' elif self.test_number > 0: when_error_happened = f' in test #{self.test_number}' else: when_error_happened = '' result = self.get_type() + when_error_happened if self.error_text: result += '\n\n' + self.error_text.strip() if self.stack_trace: result += '\n\n' + self.stack_trace.strip() full_out = OutputHandler.get_dynamic_output() full_err = str_to_stacktrace(OutputHandler.get_err()) arguments = self.__get_args() trimmed_out = self.__trim_lines(full_out) trimmed_err = self.__trim_lines(full_err) worth_showing_err = len(full_err.strip()) != 0 and full_err.strip() not in result worth_showing_out = len(full_out.strip()) != 0 and full_out.strip() not in result worth_showing_args = len(arguments.strip()) != 0 from hstest.stage_test import StageTest test_run = StageTest.curr_test_run if worth_showing_out or worth_showing_err or worth_showing_args: result += '\n\n' if worth_showing_out or worth_showing_err: result += "Please find below the output of your program during this failed test.\n" if test_run and test_run.input_used: result += "Note that the '>' character indicates the beginning of the input line.\n" result += "\n---\n\n" if worth_showing_args: result += arguments + '\n\n' if worth_showing_out: if worth_showing_err: result += 'stdout:\n' result += trimmed_out + '\n\n' if worth_showing_err: result += "stderr:\n" + trimmed_err return result.strip()
def __init__(self, test_num: int, cause: BaseException): super().__init__() self.test_number = test_num self.error_text = 'We have recorded this bug ' \ 'and will fix it soon.\n\n' + get_report() self.stack_trace = get_stacktrace(cause, hide_internals=False) if isinstance(cause, UnexpectedError) and cause.exception is not None: self.stack_trace += '\n' + get_stacktrace(cause.exception, hide_internals=False) program_stderr: str = OutputHandler.get_err() if program_stderr: self.stack_trace = self.stack_trace.strip( ) + '\n\n' + program_stderr