]> git-server-git.apps.pok.os.sepia.ceph.com Git - teuthology.git/commitdiff
util/scanner: add UnitTestScanner.num_of_total_failures 1792/head
authorVallari Agrawal <val.agl002@gmail.com>
Fri, 27 Oct 2023 08:58:18 +0000 (14:28 +0530)
committerVallari Agrawal <val.agl002@gmail.com>
Mon, 27 Nov 2023 16:25:42 +0000 (21:55 +0530)
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 <val.agl002@gmail.com>
teuthology/util/scanner.py
teuthology/util/test/test_scanner.py

index 1e140d618cdb97dc7b87c3767f4b1aa7066532ef..b67d88c92594ee3b23430ddbe9e496be2448861f 100644 (file)
@@ -89,7 +89,7 @@ class UnitTestScanner(Scanner):
                 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,
@@ -99,7 +99,16 @@ class UnitTestScanner(Scanner):
                         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'
@@ -109,7 +118,8 @@ class UnitTestScanner(Scanner):
             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))
 
index 1c7c89faa5b557e9f5e3a7f9c94cde1b99ff7bae..928d4305b7baff6ec85368508b11ddee7fecf898 100644 (file)
@@ -44,7 +44,7 @@ Reason: 'NoSuchTagSetError' != 'NoSuchTagSet'.",
         m_open.return_value = open(xml_path, "rb")
         self.remote._sftp_open_file = m_open
         result = UnitTestScanner(remote=self.remote).scan_and_write(xml_path, "test_summary.yaml")
-        assert result == self.test_values["error_msg"]
+        assert result == "(total 1 failed) " + self.test_values["error_msg"]
 
     def test_parse(self):
         xml_content = b'<?xml version="1.0" encoding="UTF-8"?>\n<testsuite name="xyz" tests="1" \