diff options
author | nkozlovskiy <nmk@ydb.tech> | 2023-08-17 14:46:47 +0300 |
---|---|---|
committer | nkozlovskiy <nmk@ydb.tech> | 2023-08-17 17:10:15 +0300 |
commit | 6b27c58711cc34acf56dca10a90ff18d5d310f2c (patch) | |
tree | aa91e796d6e538d31cbe4b60d5be42f045feb6f1 /.github/scripts | |
parent | 94b610e28ef001c9db9530909402f40fff14b356 (diff) | |
download | ydb-6b27c58711cc34acf56dca10a90ff18d5d310f2c.tar.gz |
ci: don't throw an error when empty report xml is found, also print failed test names
Diffstat (limited to '.github/scripts')
-rwxr-xr-x | .github/scripts/tests/fail-checker.py | 34 | ||||
-rwxr-xr-x | .github/scripts/tests/generate-summary.py | 25 | ||||
-rw-r--r-- | .github/scripts/tests/junit_utils.py | 28 |
3 files changed, 49 insertions, 38 deletions
diff --git a/.github/scripts/tests/fail-checker.py b/.github/scripts/tests/fail-checker.py index f71f7f117b..78ec5a25c9 100755 --- a/.github/scripts/tests/fail-checker.py +++ b/.github/scripts/tests/fail-checker.py @@ -1,24 +1,30 @@ #!/usr/bin/env python3 import argparse -import glob -import os from typing import List -import xml.etree.ElementTree as ET +from junit_utils import iter_xml_files def check_for_fail(paths: List[str]): + failed_list = [] + error_list = [] for path in paths: - for fn in glob.glob(os.path.join(path, "*.xml")): - root = ET.parse(fn).getroot() - if root.tag != "testsuite": - suites = root.findall("testsuite") - else: - suites = [root] - - for suite in suites: - if int(suite.get("failures", 0)) > 0: - print(f"::error::You have failed tests") - raise SystemExit(-1) + for fn, suite, case in iter_xml_files(path): + is_failure = case.find("failure") is not None + is_error = case.find("error") is not None + test_name = f"{case.get('classname')}::{case.get('name')}" + + if is_failure: + failed_list.append((test_name, fn)) + elif is_error: + error_list.append((test_name, fn)) + + if failed_list or error_list: + print(f"::error::You have failed tests") + for t, fn in failed_list: + print(f"failure: {t} ({fn})") + for t, fn in error_list: + print(f"error: {t} ({fn})") + raise SystemExit(-1) def main(): diff --git a/.github/scripts/tests/generate-summary.py b/.github/scripts/tests/generate-summary.py index e7dbca46eb..33d61b01f1 100755 --- a/.github/scripts/tests/generate-summary.py +++ b/.github/scripts/tests/generate-summary.py @@ -1,12 +1,10 @@ #!/usr/bin/env python3 import argparse import os -import glob import dataclasses import sys from typing import Optional, List -from xml.etree import ElementTree as ET -from junit_utils import get_property_value +from junit_utils import get_property_value, iter_xml_files @dataclasses.dataclass @@ -33,27 +31,6 @@ class SummaryEntry: return "?" -def iter_xml_files(folder_or_file): - if os.path.isfile(folder_or_file): - files = [folder_or_file] - else: - files = glob.glob(os.path.join(folder_or_file, "*.xml")) - - for fn in files: - tree = ET.parse(fn) - root = tree.getroot() - - if root.tag == "testsuite": - suites = [root] - elif root.tag == "testsuites": - suites = root.findall("testsuite") - else: - raise ValueError(f"Invalid root tag {root.tag}") - for suite in suites: - for case in suite.findall("testcase"): - yield fn, suite, case - - def parse_junit(folder_or_file): result = [] for fn, suite, case in iter_xml_files(folder_or_file): diff --git a/.github/scripts/tests/junit_utils.py b/.github/scripts/tests/junit_utils.py index cca04b2521..fd636884cf 100644 --- a/.github/scripts/tests/junit_utils.py +++ b/.github/scripts/tests/junit_utils.py @@ -1,3 +1,5 @@ +import os +import glob from xml.etree import ElementTree as ET @@ -63,3 +65,29 @@ def suite_case_iterator(root): for case in suite.findall("testcase"): cls, method = case.attrib["classname"], case.attrib["name"] yield suite, case, cls, method + + +def iter_xml_files(folder_or_file): + if os.path.isfile(folder_or_file): + files = [folder_or_file] + else: + files = glob.glob(os.path.join(folder_or_file, "*.xml")) + + for fn in files: + try: + tree = ET.parse(fn) + except ET.ParseError as e: + print(f"Unable to parse {fn}: {e}") + continue + + root = tree.getroot() + + if root.tag == "testsuite": + suites = [root] + elif root.tag == "testsuites": + suites = root.findall("testsuite") + else: + raise ValueError(f"Invalid root tag {root.tag}") + for suite in suites: + for case in suite.findall("testcase"): + yield fn, suite, case |