diff options
author | Nikita Kozlovskiy <nikitka@gmail.com> | 2023-06-02 16:01:55 +0000 |
---|---|---|
committer | nkozlovskiy <nmk@ydb.tech> | 2023-06-02 19:01:55 +0300 |
commit | 3332cdd408c34bd067db2bde8bc0f322e392946b (patch) | |
tree | 55b852d30a65cc02e030d13e8279da13551813a4 /.github/scripts/tests/junit-postprocess.py | |
parent | 7b0b68668aa4e020c44ab92b637620432c15ecd3 (diff) | |
download | ydb-3332cdd408c34bd067db2bde8bc0f322e392946b.tar.gz |
ci: test muting
ci: test muting
Pull Request resolved: #240
Diffstat (limited to '.github/scripts/tests/junit-postprocess.py')
-rwxr-xr-x | .github/scripts/tests/junit-postprocess.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/.github/scripts/tests/junit-postprocess.py b/.github/scripts/tests/junit-postprocess.py new file mode 100755 index 0000000000..b704eb02e2 --- /dev/null +++ b/.github/scripts/tests/junit-postprocess.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +import os +import glob +import argparse +import xml.etree.ElementTree as ET +from mute_utils import mute_target, update_suite_info, MutedTestCheck + + +def case_iterator(root): + for case in root.findall("testcase"): + cls, method = case.attrib["classname"], case.attrib["name"] + yield case, cls, method + + +def mute_junit(is_mute_test, folder, dry_run): + for fn in glob.glob(os.path.join(folder, "*.xml")): + tree = ET.parse(fn) + root = tree.getroot() + total_muted = 0 + for suite in root.findall("testsuite"): + muted_cnt = 0 + for case, cls, method in case_iterator(suite): + if is_mute_test(cls, method): + if mute_target(case): + print(f"mute {cls}::{method}") + muted_cnt += 1 + + if muted_cnt: + update_suite_info(suite, n_skipped=muted_cnt, n_remove_failures=muted_cnt) + total_muted += muted_cnt + + if total_muted: + update_suite_info(root, n_skipped=total_muted, n_remove_failures=total_muted) + + print(f"{'(dry-run) ' if dry_run else ''}patch {fn}") + + if not dry_run: + tree.write(fn, xml_declaration=True, encoding="UTF-8") + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--filter-file", required=True) + parser.add_argument("--dry-run", action="store_true", default=False) + parser.add_argument("yunit_path") + args = parser.parse_args() + + if not os.path.isdir(args.yunit_path): + print(f"{args.yunit_path} is not a directory, exit") + raise SystemExit(-1) + + # FIXME: add gtest filter file ? + is_mute_test = MutedTestCheck(args.filter_file) + + if not is_mute_test.has_rules: + print("nothing to mute") + return + + mute_junit(is_mute_test, args.yunit_path, args.dry_run) + + +if __name__ == "__main__": + main() |