|
4 | 4 | import types |
5 | 5 |
|
6 | 6 | import click |
| 7 | +from junitparser import TestCase, TestSuite # type: ignore |
7 | 8 |
|
8 | 9 | from launchable.commands.detect_flakes import detect_flakes as detect_flakes_cmd |
9 | 10 | from launchable.commands.record.tests import tests as record_tests_cmd |
10 | 11 | from launchable.commands.split_subset import split_subset as split_subset_cmd |
11 | 12 | from launchable.commands.subset import subset as subset_cmd |
12 | 13 |
|
| 14 | +from ..testpath import TestPath |
| 15 | + |
13 | 16 |
|
14 | 17 | def cmdname(m): |
15 | 18 | """figure out the sub-command name from a test runner function""" |
@@ -113,6 +116,47 @@ def record_tests(client, source_roots): |
113 | 116 |
|
114 | 117 | return wrap(record_tests, record_tests_cmd, self.cmdname) |
115 | 118 |
|
| 119 | + def file_profile_report_files(self): |
| 120 | + """ |
| 121 | + Suitable for test runners that create a directory full of JUnit report files. |
| 122 | +
|
| 123 | + 'record tests' expect JUnit report/XML file names. |
| 124 | + """ |
| 125 | + |
| 126 | + @click.argument('source_roots', required=True, nargs=-1) |
| 127 | + def record_tests(client, source_roots): |
| 128 | + def path_builder( |
| 129 | + case: TestCase, suite: TestSuite, report_file: str |
| 130 | + ) -> TestPath: |
| 131 | + def find_filename(): |
| 132 | + """look for what looks like file names from test reports""" |
| 133 | + for e in [case, suite]: |
| 134 | + for a in ["file", "filepath"]: |
| 135 | + filepath = e._elem.attrib.get(a) |
| 136 | + if filepath: |
| 137 | + return filepath |
| 138 | + return None # failing to find a test name |
| 139 | + |
| 140 | + filepath = find_filename() |
| 141 | + if not filepath: |
| 142 | + raise click.ClickException("No file name found in %s" % report_file) |
| 143 | + |
| 144 | + # default test path in `subset` expects to have this file name |
| 145 | + test_path = [client.make_file_path_component(filepath)] |
| 146 | + if suite.name: |
| 147 | + test_path.append({"type": "testsuite", "name": suite.name}) |
| 148 | + if case.name: |
| 149 | + test_path.append({"type": "testcase", "name": case.name}) |
| 150 | + return test_path |
| 151 | + |
| 152 | + client.path_builder = path_builder |
| 153 | + |
| 154 | + for r in source_roots: |
| 155 | + client.report(r) |
| 156 | + client.run() |
| 157 | + |
| 158 | + return wrap(record_tests, record_tests_cmd, self.cmdname) |
| 159 | + |
116 | 160 | @classmethod |
117 | 161 | def load_report_files(cls, client, source_roots, file_mask="*.xml"): |
118 | 162 | # client type: RecordTests in def launchable.commands.record.tests.tests |
|
0 commit comments