diff --git a/conftest.py b/conftest.py index 72b4b598891c..0e587e7d314e 100644 --- a/conftest.py +++ b/conftest.py @@ -76,6 +76,12 @@ def pytest_collection() -> None: "CUDA_VISIBLE_DEVICES", str(xdist_worker_number % num_cuda_devices) ) +_USE_ROCM_ABORT_DETECTOR_PLUGIN = bool( + os.environ.get("PYTEST_ABORT_LAST_RUNNING_FILE") + or os.environ.get("PYTEST_ABORT_LAST_RUNNING_DIR") +) + + class ThreadSafeTestLogger: """Thread-safe logging for parallel test execution and abort detection""" def __init__(self): @@ -171,8 +177,7 @@ def clear_running_test(self, test_file): os.remove(log_file) -# Global logger instance -test_logger = ThreadSafeTestLogger() +test_logger = ThreadSafeTestLogger() if not _USE_ROCM_ABORT_DETECTOR_PLUGIN else None @pytest.hookimpl(hookwrapper=True) @@ -183,6 +188,10 @@ def pytest_runtest_protocol(item, nextitem): when the test completes successfully. If the test crashes, the file remains and can be detected by the test runner. """ + if _USE_ROCM_ABORT_DETECTOR_PLUGIN or test_logger is None: + outcome = yield + return outcome + test_file = test_logger.get_test_file_name(item.session) test_name = item.name nodeid = item.nodeid @@ -230,6 +239,9 @@ def pytest_sessionfinish(session, exitstatus): If a crash file still exists, it means a test crashed and the runner will detect it. We just report it here for visibility. """ + if _USE_ROCM_ABORT_DETECTOR_PLUGIN or test_logger is None: + return + test_file = test_logger.get_test_file_name(session) log_file = f"{test_logger.base_dir}/{test_file}_last_running.json"