def report_fail(self, test, fail_type, err): # workaround nose bug on python 3 if is_string(err[1]): err = (err[0], Exception(err[1]), err[2]) test_id = self.get_test_id(test) details = convert_error_to_string(err) start_index = details.find(_captured_output_start_marker) end_index = details.find(_captured_output_end_marker) if 0 <= start_index < end_index: # do not log test output twice, see report_finish for actual output handling details = details[:start_index] + details[end_index + len(_captured_output_end_marker):] try: error = err[1] if isinstance(error, EqualsAssertionError): details = convert_error_to_string(err, 2) self.messages.testFailed(test_id, message=error.msg, details=details, flowId=test_id, comparison_failure=error) return except Exception: pass self.messages.testFailed(test_id, message=fail_type, details=details, flowId=test_id)
def addSubTest(self, test, subtest, err): super(TeamcityTestResult, self).addSubTest(test, subtest, err) test_id = self.get_test_id(test) subtest_id = self.get_test_id(subtest) if subtest_id.startswith(test_id): block_id = subtest_id[len(test_id):].strip() else: block_id = subtest_id if len(block_id) == 0: block_id = subtest_id if err is not None: self.add_subtest_failure(test_id, block_id) if issubclass(err[0], test.failureException): self.messages.blockOpened(block_id, flowId=test_id) self.messages.testStdErr(test_id, out="SubTest failure: %s\n" % convert_error_to_string(err), flowId=test_id) self.messages.blockClosed(block_id, flowId=test_id) else: self.messages.blockOpened(block_id, flowId=test_id) self.messages.testStdErr(test_id, out="SubTest error: %s\n" % convert_error_to_string(err), flowId=test_id) self.messages.blockClosed(block_id, flowId=test_id) else: self.messages.blockOpened(block_id, flowId=test_id) self.messages.blockClosed(block_id, flowId=test_id)
def addSubTest(self, test, subtest, err): _super = super(TeamcityTestResult, self) if hasattr(_super, "addSubTest"): _super.addSubTest(test, subtest, err) test_id = self.get_test_id(test) subtest_id = self.get_test_id(subtest) if subtest_id.startswith(test_id): # Replace "." -> "_" since '.' is a test hierarchy separator # See i.e. https://github.com/JetBrains/teamcity-messages/issues/134 (https://youtrack.jetbrains.com/issue/PY-23846) block_id = subtest_id[len(test_id):].strip().replace(".", "_") else: block_id = subtest_id if len(block_id) == 0: block_id = subtest_id if err is not None: self.add_subtest_failure(test_id, block_id) if issubclass(err[0], test.failureException): self.messages.subTestBlockOpened(block_id, subTestResult="Failure", flowId=test_id) self.messages.testStdErr(test_id, out="SubTest failure: %s\n" % convert_error_to_string(err), flowId=test_id) self.messages.blockClosed(block_id, flowId=test_id) else: self.messages.subTestBlockOpened(block_id, subTestResult="Error", flowId=test_id) self.messages.testStdErr(test_id, out="SubTest error: %s\n" % convert_error_to_string(err), flowId=test_id) self.messages.blockClosed(block_id, flowId=test_id) else: self.messages.subTestBlockOpened(block_id, subTestResult="Success", flowId=test_id) self.messages.blockClosed(block_id, flowId=test_id)
def addExpectedFailure(self, test, err): super(TeamcityTestResult, self).addExpectedFailure(test, err) err = convert_error_to_string(err) test_id = self.get_test_id(test) self.messages.testIgnored(test_id, message="Expected failure: " + err, flowId=test_id)
def report(self, morfs, outfile=None): self.find_code_units(morfs) total = Numbers() for cu in self.code_units: try: analysis = self.coverage._analyze(cu) nums = analysis.numbers total += nums except KeyboardInterrupt: raise except: if self.config.ignore_errors: continue err = sys.exc_info() typ, msg = err[:2] if typ is NotPython and not cu.should_be_python(): continue test_id = cu.name details = convert_error_to_string(err) self.messages.testStarted(test_id, flowId=test_id) self.messages.testFailed(test_id, message="Coverage analysis failed", details=details, flowId=test_id) self.messages.testFinished(test_id, flowId=test_id) if total.n_files > 0: covered = total.n_executed + (total.n_executed_branches if self.branches else 0) total_statements = total.n_statements + (total.n_branches if self.branches else 0) self.messages.buildStatisticLinesCovered(covered) self.messages.buildStatisticTotalLines(total_statements) self.messages.buildStatisticLinesUncovered(total_statements - covered)
def report_fail(self, test, fail_type, err): test_id = self.get_test_id(test) diff_failed = None try: error = err[1] if isinstance(error, EqualsAssertionError): diff_failed = error except: pass if is_string(err): details = err elif get_class_fullname(err) == "twisted.python.failure.Failure": details = err.getTraceback() else: frames_to_skip_from_tail = 2 if diff_failed else 0 details = convert_error_to_string(err, frames_to_skip_from_tail) subtest_failures = self.get_subtest_failure(test_id) if subtest_failures: details = "Failed subtests list: " + subtest_failures + "\n\n" + details.strip() details = details.strip() if diff_failed: self.messages.testFailed(test_id, message=diff_failed.msg, details=details, flowId=test_id, comparison_failure=diff_failed) else: self.messages.testFailed(test_id, message=fail_type, details=details, flowId=test_id) self.failed_tests.add(test_id)
def report_fail(self, test, fail_type, err): # workaround nose bug on python 3 if is_string(err[1]): err = (err[0], Exception(err[1]), err[2]) test_id = self.get_test_id(test) details = convert_error_to_string(err) start_index = details.find(_captured_output_start_marker) end_index = details.find(_captured_output_end_marker) if 0 <= start_index < end_index: captured_output = details[start_index + len(_captured_output_start_marker ):end_index] details = details[:start_index] + details[ end_index + len(_captured_output_end_marker):] for chunk in split_output(limit_output(captured_output)): self.messages.testStdOut(test_id, chunk, flowId=test_id) self.messages.testFailed(test_id, message=fail_type, details=details, flowId=test_id)
def report_fail(self, test, fail_type, err): test_id = self.get_test_id(test) diff_failed = None try: error = err[1] if isinstance(error, EqualsAssertionError): diff_failed = error except Exception: pass if is_string(err): details = err else: try: details = err.getTraceback() except AttributeError: frames_to_skip_from_tail = 2 if diff_failed else 0 details = convert_error_to_string(err, frames_to_skip_from_tail) subtest_failures = self.get_subtest_failure(test_id) if subtest_failures: details = "Failed subtests list: " + subtest_failures + "\n\n" + details.strip() details = details.strip() if diff_failed: self.messages.testFailed(test_id, message=diff_failed.msg, details=details, flowId=test_id, comparison_failure=diff_failed) else: self.messages.testFailed(test_id, message=fail_type, details=details, flowId=test_id) self.failed_tests.add(test_id)
def report_fail(self, test, fail_type, err): test_id = self.get_test_id_with_description(test) diff_failed = None try: from .jb_local_exc_store import get_exception error = get_exception() if isinstance(error, EqualsAssertionError): diff_failed = error except Exception: pass if is_string(err): details = err else: try: details = err.getTraceback() except AttributeError: details = convert_error_to_string(err, ["diff_tools", "case.py"]) subtest_failures = self.get_subtest_failure(test_id) if subtest_failures: details = "Failed subtests list: " + subtest_failures + "\n\n" + details.strip() details = details.strip() if diff_failed: self.messages.testFailed(test_id, message=diff_failed.msg, details=details, flowId=test_id, comparison_failure=diff_failed) else: self.messages.testFailed(test_id, message=fail_type, details=details, flowId=test_id) self.failed_tests.add(test_id)
def addExpectedFailure(self, test, err): _super = super(TeamcityTestResult, self) if hasattr(_super, "addExpectedFailure"): _super.addExpectedFailure(test, err) err = convert_error_to_string(err) test_id = self.get_test_id_with_description(test) self.messages.testIgnored(test_id, message="Expected failure: " + err, flowId=test_id)
def report(self, morfs, outfile=None): if hasattr(self, 'find_code_units'): self.find_code_units(morfs) else: self.find_file_reporters(morfs) total = Numbers() if hasattr(self, 'code_units'): units = self.code_units else: units = self.file_reporters for cu in units: try: analysis = self.coverage._analyze(cu) nums = analysis.numbers total += nums except KeyboardInterrupt: raise except Exception: if self.config.ignore_errors: continue err = sys.exc_info() typ, msg = err[:2] if typ is NotPython and not cu.should_be_python(): continue test_id = cu.name details = convert_error_to_string(err) self.messages.testStarted(test_id, flowId=test_id) self.messages.testFailed( test_id, message="Coverage analysis failed", details=details, flowId=test_id) self.messages.testFinished(test_id, flowId=test_id) if total.n_files > 0: covered = total.n_executed total_statements = total.n_statements if self.branches: covered += total.n_executed_branches total_statements += total.n_branches self.messages.buildStatisticLinesCovered(covered) self.messages.buildStatisticTotalLines(total_statements) self.messages.buildStatisticLinesUncovered( total_statements - covered)
def report_fail(self, test, fail_type, err): test_id = self.get_test_id(test) if is_string(err): details = err else: details = convert_error_to_string(err) subtest_failure = self.get_subtest_failure(test_id) if subtest_failure: details = subtest_failure + "\n" + details self.messages.testFailed(test_id, message=fail_type, details=details, flowId=test_id) self.failed_tests.add(test_id)
def report_fail(self, test, fail_type, err): test_id = self.get_test_id(test) if is_string(err): details = err elif get_class_fullname(err) == "twisted.python.failure.Failure": details = err.getTraceback() else: details = convert_error_to_string(err) subtest_failure = self.get_subtest_failure(test_id) if subtest_failure: details = subtest_failure + "\n" + details self.messages.testFailed(test_id, message=fail_type, details=details, flowId=test_id) self.failed_tests.add(test_id)
def report_fail(self, test, fail_type, err): # workaround nose bug on python 3 if is_string(err[1]): err = (err[0], Exception(err[1]), err[2]) test_id = self.get_test_id(test) details = convert_error_to_string(err) start_index = details.find(_captured_output_start_marker) end_index = details.find(_captured_output_end_marker) if 0 <= start_index < end_index: # do not log test output twice, see report_finish for actual output handling details = details[:start_index] + details[end_index + len(_captured_output_end_marker):] self.messages.testFailed(test_id, message=fail_type, details=details, flowId=test_id)
def report_fail(self, test, fail_type, err): # workaround nose bug on python 3 if is_string(err[1]): err = (err[0], Exception(err[1]), err[2]) test_id = self.get_test_id(test) details = convert_error_to_string(err) start_index = details.find(_captured_output_start_marker) end_index = details.find(_captured_output_end_marker) if 0 <= start_index < end_index: captured_output = details[start_index + len(_captured_output_start_marker):end_index] details = details[:start_index] + details[end_index + len(_captured_output_end_marker):] for chunk in split_output(limit_output(captured_output)): self.messages.testStdOut(test_id, chunk, flowId=test_id) self.messages.testFailed(test_id, message=fail_type, details=details, flowId=test_id)
def add_subtest_failure(self, test_id, subtest_id, err): fail_array = self.subtest_failures.get(test_id, []) fail_array.append("%s:\n%s" % (subtest_id, convert_error_to_string(err))) self.subtest_failures[test_id] = fail_array