2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-03-22 17:27:01 +00:00
|
|
|
tests.support.generate-from-names-from-failed-test-reports
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
This script is meant as a stop-gap until we move to PyTest to provide a functionality similar to
|
|
|
|
PyTest's --last-failed where PyTest only runs last failed tests.
|
2020-04-02 20:10:20 -05:00
|
|
|
"""
|
2019-04-02 01:01:34 +01:00
|
|
|
# pylint: disable=resource-leakage
|
2020-04-02 20:10:20 -05:00
|
|
|
|
2019-03-22 17:27:01 +00:00
|
|
|
import argparse
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
try:
|
|
|
|
import xunitparser
|
|
|
|
except ImportError:
|
|
|
|
sys.stderr.write(
|
|
|
|
"Please install the xunitparser python package to run this script\n"
|
|
|
|
)
|
|
|
|
sys.stderr.flush()
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
REPO_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
|
|
"--reports-dir",
|
|
|
|
default=os.path.join(REPO_ROOT, "artifacts", "xml-unittests-output"),
|
|
|
|
help="Path to the directory where the JUnit XML reports can be found",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"output_file",
|
2021-08-03 08:40:21 +01:00
|
|
|
help=(
|
|
|
|
"Path to the file containing the failed tests listing to be fed to"
|
|
|
|
" --names-files"
|
|
|
|
),
|
2019-03-22 17:27:01 +00:00
|
|
|
)
|
|
|
|
options = parser.parse_args()
|
|
|
|
total_xml_reports = 0
|
|
|
|
failures = set()
|
|
|
|
for fname in sorted(glob.glob(os.path.join(options.reports_dir, "*.xml"))):
|
|
|
|
total_xml_reports += 1
|
2024-02-25 10:37:08 +00:00
|
|
|
with open(fname, encoding="utf-8") as rfh:
|
2019-03-22 17:27:01 +00:00
|
|
|
test_suite, test_result = xunitparser.parse(rfh)
|
|
|
|
if not test_result.errors and not test_result.failures:
|
|
|
|
continue
|
|
|
|
for test in test_suite:
|
|
|
|
if test.bad:
|
|
|
|
failures.add("{classname}.{methodname}".format(**test.__dict__))
|
|
|
|
|
|
|
|
if not total_xml_reports:
|
|
|
|
parser.exit(status=1, message="No JUnit XML files were parsed")
|
|
|
|
|
2024-02-25 10:37:08 +00:00
|
|
|
with open(options.output_file, "w", encoding="utf-8") as wfh:
|
2019-03-22 17:27:01 +00:00
|
|
|
wfh.write(os.linesep.join(sorted(failures)))
|
|
|
|
|
|
|
|
parser.exit(status=0)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|