浏览代码

minor fixes to script

Signed-off-by: Chiang <[email protected]>
Chiang 2 年之前
父节点
当前提交
5565261c0f
共有 2 个文件被更改,包括 26 次插入20 次删除
  1. 11 2
      scripts/build/Platform/Windows/build_config.json
  2. 15 18
      scripts/metrics/pytest_metrics_xml_to_csv.py

+ 11 - 2
scripts/build/Platform/Windows/build_config.json

@@ -5,11 +5,12 @@
     ],
     "steps": [
       "test_cpu_profile_internal_metrics",
-      "generate_metrics",
+      "generate_ctest_metrics",
+      "generate_pytest_metrics",
       "upload_metrics"
     ]
   },
-  "generate_metrics": {
+  "generate_ctest_metrics": {
     "TAGS": [],
     "COMMAND": "python_windows.cmd",
     "PARAMETERS": {
@@ -17,6 +18,14 @@
       "SCRIPT_PARAMETERS": "build\\windows --output-directory build\\windows\\Testing\\csv --branch %BRANCH_NAME% -w"
     }
   },
+  "generate_pytest_metrics": {
+    "TAGS": [],
+    "COMMAND": "python_windows.cmd",
+    "PARAMETERS": {
+      "SCRIPT_PATH": "scripts\\metrics\\pytest_metrics_xml_to_csv.py",
+      "SCRIPT_PARAMETERS": "build\\windows\\Testing\\Pytest --output-directory build\\windows\\Testing\\csv --branch %BRANCH_NAME% -w"
+    }
+  },
   "upload_metrics": {
     "TAGS": [],
     "COMMAND": "upload_metrics_windows.cmd",

+ 15 - 18
scripts/metrics/pytest_metrics_xml_to_csv.py

@@ -136,30 +136,27 @@ def parse_pytest_xmls_to_csv(full_xml_path, writer):
     xml_root = xmlElementTree.parse(full_xml_path).getroot()
     test_data_dict = {}
     # Each PyTest test module will have a Test entry
-    try:
-        for test in xml_root.findall('./testsuite/testcase'):
-            # There are some testcase fields that are not tests. They do not have 'name' attributes are skipped
-            if 'name' not in test.attrib:
-                logger.debug(f'We found a testcase where it did not have a test field. Printing attribs:\n'
-                             f'{test.attrib}')
-                continue
+    for test in xml_root.findall('./testsuite/testcase'):
+        try:
             test_data_dict['test_name'] = test.attrib['name']
             test_data_dict['duration_seconds'] = float(test.attrib['time'])
             # using 'status' to keep it consistent with CTest xml schema
             test_data_dict['status'] = _determine_test_result(test)
             # replace slashes to match codeowners file
             test_file_path = test.attrib['file'].replace("\\", "/")
-            try:
-                sig_owner = SIG_OWNER_CACHE[test_file_path]
-            except KeyError:
-                # Index 1 is the sig owner
-                sig_owner = codeowners_hint.get_codeowners(test_file_path)[1]
-                SIG_OWNER_CACHE[test_file_path] = sig_owner
-            test_data_dict['sig_owner'] = sig_owner if sig_owner else "N/A"
-
-            writer.writerow(test_data_dict)
-    except KeyError as exc:
-        logger.exception(f"KeyError when parsing xml file: {full_xml_path}. Check xml keys for changes.", exc)
+        except KeyError as exc:
+            logger.exception(f"KeyError when parsing xml file: {full_xml_path}. Check xml keys for changes. Printing"
+                             f"attribs:\n{test.attrib}", exc)
+            continue
+        if sig_owner in SIG_OWNER_CACHE:
+            sig_owner = SIG_OWNER_CACHE[test_file_path]
+        else:
+            # Index 1 is the sig owner
+            _, sig_owner, _ = codeowners_hint.get_codeowners(test_file_path)
+            SIG_OWNER_CACHE[test_file_path] = sig_owner
+        test_data_dict['sig_owner'] = sig_owner if sig_owner else "N/A"
+
+        writer.writerow(test_data_dict)
 
 
 if __name__ == "__main__":