Skip to content

Commit 594a0db

Browse files
committed
Add --retag mode to new runner
1 parent cd065a8 commit 594a0db

File tree

1 file changed

+37
-4
lines changed
  • graalpython/com.oracle.graal.python.test/src

1 file changed

+37
-4
lines changed

graalpython/com.oracle.graal.python.test/src/runner.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,11 @@ def from_str(cls, s: str):
132132

133133
@classmethod
134134
def from_test_case(cls, test_file: Path, test: unittest.TestCase):
135-
return cls(test_file, test.id())
135+
test_id = test.id()
136+
if type(test).id is not unittest.TestCase.id:
137+
# Qualify doctests so that we know what they are
138+
test_id = f'{type(test).__qualname__}.{test_id}'
139+
return cls(test_file, test_id)
136140

137141

138142
@dataclass
@@ -288,10 +292,10 @@ def test_path_to_module(path: Path):
288292

289293

290294
class TestRunner:
291-
def __init__(self, *, failfast, report_durations):
295+
def __init__(self, *, failfast: bool, report_durations: int | None):
292296
self.failfast = failfast
293297
self.report_durations = report_durations
294-
self.results = []
298+
self.results: list[TestResult] = []
295299
self.total_duration = 0.0
296300

297301
@staticmethod
@@ -399,6 +403,21 @@ def generate_mx_report(self, path: str):
399403
# noinspection PyTypeChecker
400404
json.dump(report_data, f)
401405

406+
def generate_tags(self):
407+
by_file = defaultdict(list)
408+
for result in self.results:
409+
by_file[result.test_id.test_file].append(result)
410+
for test_file, results in by_file.items():
411+
config = config_for_file(test_file)
412+
tag_file = config.get_tag_file(test_file)
413+
if not tag_file:
414+
log(f"WARNNING: no tag directory for test file {result.test_id.test_file}")
415+
continue
416+
with open(tag_file, 'w') as f:
417+
for result in results:
418+
if result.status == TestStatus.SUCCESS:
419+
f.write(f'*graalpython.lib-python.3.{result.test_id.test_name}\n')
420+
402421

403422
def interrupt_process(process: subprocess.Popen):
404423
sig = signal.SIGINT if sys.platform != 'win32' else signal.CTRL_C_EVENT
@@ -640,6 +659,10 @@ def is_partial_splits_individual_tests(self, test_file: Path):
640659
name = str(resolved).removesuffix('.py')
641660
return name in self.partial_splits_individual_tests
642661

662+
def get_tag_file(self, test_file: Path):
663+
if self.tags_dir:
664+
return self.tags_dir / (test_file.name.removesuffix('.py') + '.txt')
665+
643666

644667
@lru_cache
645668
def config_for_dir(path: Path) -> Config:
@@ -803,7 +826,7 @@ def collect(all_specifiers: list[TestSpecifier], *, use_tags=False, ignore=None,
803826

804827

805828
def read_tags(test_file: Path, config: Config) -> list[TestId]:
806-
tag_file = config.tags_dir / (test_file.name.removesuffix('.py') + '.txt')
829+
tag_file = config.get_tag_file(test_file)
807830
tags = []
808831
if tag_file.exists():
809832
with open(tag_file) as f:
@@ -864,6 +887,8 @@ def main():
864887
help="Exit immediately after the first failure")
865888
parser.add_argument('--all', action='store_true',
866889
help="Run tests that are normally not enabled due to tags")
890+
parser.add_argument('--retag', action='store_true',
891+
help="Run tests and regenerate tags based on the results. Implies --all, --tagged and -n")
867892
parser.add_argument('--collect-only', action='store_true',
868893
help="Print found tests IDs without running tests")
869894
parser.add_argument('--durations', type=int, default=0,
@@ -894,6 +919,11 @@ def main():
894919

895920
args = parser.parse_args()
896921

922+
if args.retag:
923+
args.all = True
924+
args.tagged = True
925+
args.num_processes = args.num_processes or 1
926+
897927
if get_bool_env('GRAALPYTEST_FAIL_FAST'):
898928
args.failfast = True
899929

@@ -948,6 +978,9 @@ def main():
948978
runner.run_tests(tests)
949979
if args.mx_report:
950980
runner.generate_mx_report(args.mx_report)
981+
if args.retag:
982+
runner.generate_tags()
983+
return
951984
if runner.tests_failed():
952985
sys.exit(1)
953986

0 commit comments

Comments
 (0)