|
49 | 49 | from .trt_test_alternative import (call, check_output, exists, is_windows, |
50 | 50 | is_wsl, makedirs, print_info, print_warning, |
51 | 51 | wsl_to_win_path) |
| 52 | +from .utils.periodic_junit import PeriodicJUnitXML |
52 | 53 |
|
53 | 54 | try: |
54 | 55 | from llm import trt_environment |
@@ -2095,6 +2096,33 @@ def pytest_addoption(parser): |
2095 | 2096 | "Specify test model suites separated by semicolons or spaces. Each suite can contain special characters. " |
2096 | 2097 | "Example: --test-model-suites=suite1;suite2;suite3 or --test-model-suites=suite1 suite2 suite3", |
2097 | 2098 | ) |
| 2099 | + parser.addoption( |
| 2100 | + "--periodic-junit", |
| 2101 | + action="store_true", |
| 2102 | + default=False, |
| 2103 | + help= |
| 2104 | + "Enable periodic JUnit XML reporter. This reporter leverages pytest's built-in junitxml " |
| 2105 | + "for reliable test result handling. Saves progress periodically to prevent data loss on " |
| 2106 | + "interruption. Requires --output-dir to be set.", |
| 2107 | + ) |
| 2108 | + parser.addoption( |
| 2109 | + "--periodic-interval", |
| 2110 | + action="store", |
| 2111 | + type=int, |
| 2112 | + default=18000, |
| 2113 | + help= |
| 2114 | + "Time interval in seconds between periodic saves (default: 18000s = 5 hours). " |
| 2115 | + "Only used with --periodic-junit.", |
| 2116 | + ) |
| 2117 | + parser.addoption( |
| 2118 | + "--periodic-batch-size", |
| 2119 | + action="store", |
| 2120 | + type=int, |
| 2121 | + default=10, |
| 2122 | + help= |
| 2123 | + "Number of completed tests before triggering a periodic save (default: 10). " |
| 2124 | + "Only used with --periodic-junit.", |
| 2125 | + ) |
2098 | 2126 |
|
2099 | 2127 |
|
2100 | 2128 | @pytest.hookimpl(trylast=True) |
@@ -2196,6 +2224,40 @@ def pytest_configure(config): |
2196 | 2224 | if config.getoption("--run-ray"): |
2197 | 2225 | os.environ["TLLM_DISABLE_MPI"] = "1" |
2198 | 2226 |
|
| 2227 | + # Initialize PeriodicJUnitXML reporter if enabled |
| 2228 | + periodic = config.getoption("--periodic-junit", default=False) |
| 2229 | + output_dir = config.getoption("--output-dir", default=None) |
| 2230 | + |
| 2231 | + if periodic and output_dir: |
| 2232 | + periodic_interval = config.getoption("--periodic-interval") |
| 2233 | + periodic_batch_size = config.getoption("--periodic-batch-size") |
| 2234 | + |
| 2235 | + # Create the reporter with logger |
| 2236 | + xmlpath = os.path.join(output_dir, "results.xml") |
| 2237 | + reporter = PeriodicJUnitXML( |
| 2238 | + xmlpath=xmlpath, |
| 2239 | + interval=periodic_interval, |
| 2240 | + batch_size=periodic_batch_size, |
| 2241 | + logger={ |
| 2242 | + 'info': print_info, |
| 2243 | + 'warning': print_warning |
| 2244 | + }, |
| 2245 | + ) |
| 2246 | + |
| 2247 | + # Configure and register the reporter |
| 2248 | + reporter.pytest_configure(config) |
| 2249 | + config.pluginmanager.register(reporter, 'periodic_junit') |
| 2250 | + |
| 2251 | + print_info("PeriodicJUnitXML reporter registered") |
| 2252 | + print_info( |
| 2253 | + f" Interval: {periodic_interval}s ({periodic_interval/60:.1f} min)" |
| 2254 | + ) |
| 2255 | + print_info(f" Batch size: {periodic_batch_size} tests") |
| 2256 | + elif periodic and not output_dir: |
| 2257 | + print_warning( |
| 2258 | + "Warning: --periodic-junit requires --output-dir to be set. " |
| 2259 | + "Periodic reporting disabled.") |
| 2260 | + |
2199 | 2261 |
|
2200 | 2262 | def deselect_by_test_model_suites(test_model_suites, items, test_prefix, |
2201 | 2263 | config): |
|
0 commit comments