Skip to content

Commit

Permalink
util/scanner: add UnitTestScanner.num_of_total_failures
Browse files Browse the repository at this point in the history
In UnitTestScanner's final error message, add total count of failures
before the first error occurance, like "(total x failed) <message>".
Another minor change: add "..." if the failure reason is more than 200 chars.

Signed-off-by: Vallari Agrawal <[email protected]>
  • Loading branch information
VallariAg committed Oct 27, 2023
1 parent c4bef53 commit bef9b3e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions teuthology/util/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _parse(self, file_content: str) -> Tuple[Optional[str], Optional[dict]]:
if child.tag in ['failure', 'error']:
fault_kind = child.tag
reason = child.get('message', 'No message found in xml output, check logs.')
short_reason = reason[:200]
short_reason = (reason[:200].strip() + '...') if len(reason) > 200 else reason.strip()
error_data[testcase_suitename] += [{
"kind": fault_kind,
"testcase": testcase_name,
Expand All @@ -99,7 +99,16 @@ def _parse(self, file_content: str) -> Tuple[Optional[str], Optional[dict]]:
exception_txt = f'{fault_kind.upper()}: Test `{testcase_name}` of `{testcase_suitename}`. Reason: {short_reason}.'

return exception_txt, { "failed_testsuites": dict(error_data), "num_of_failures": len(failed_testcases) }


@property
def num_of_total_failures(self):
total_failed_testcases = 0
if self.summary_data:
for file_data in self.summary_data:
failed_tests = file_data.get("num_of_failures", 0)
total_failed_testcases += failed_tests
return total_failed_testcases

def scan_and_write(self, path_regex: str, summary_path: str) -> Optional[str]:
"""
Scan all files matching 'path_regex'
Expand All @@ -109,7 +118,8 @@ def scan_and_write(self, path_regex: str, summary_path: str) -> Optional[str]:
errors = self.scan_all_files(path_regex)
self.write_summary(summary_path)
if errors:
return errors[0]
count = self.num_of_total_failures
return f"(total {count} failed) " + errors[0]
except Exception as scanner_exc:
log.error(str(scanner_exc))

Expand Down

0 comments on commit bef9b3e

Please sign in to comment.