Developer Tools

PyTorch fixes test name detection for Git-style paths on Windows

A cross-platform bug was preventing test prioritization on Windows CI runners.

Deep Dive

PyTorch's CI relies on target-determination heuristics to prioritize running tests for files changed in a pull request. Two key heuristics—`EditedByPR` and `PreviouslyFailedInPR—use` the helper function `python_test_file_to_test_name()` to convert changed test-file paths into test names. The helper checks if a path starts with `test{os.path.sep}`, where `os.path.sep` is platform-dependent. On Windows this expects `test\`, but Git and GitHub always provide repo-relative paths using forward slashes (`test/test_jit.py`). Consequently, a directly edited test file reported with Git-style separators was ignored on Windows, weakening the signal that should have prioritized that test.

The PR, authored with AI assistance and reviewed by a contributor, fixes the issue by normalizing path separators before applying the prefix check. After the fix, both `test/test_jit.py` and `test\test_nn.py` are correctly identified as test files. The change is intentionally narrow: only the shared helper’s separator handling is modified. Non-test paths, non-Python files, scoring behavior, GitHub API fetching, merge-base logic, and test execution remain unchanged. Regression tests were added to cover both slash and backslash paths while still ignoring non-test files. This simple one-line fix ensures that test prioritization works consistently across Linux, macOS, and Windows, improving CI efficiency for PyTorch contributors on all platforms.

Key Points
  • Fix normalizes path separators in `python_test_file_to_test_name()` before matching the `test/` prefix.
  • Bug caused Git-style forward-slash paths to be missed on Windows, weakening edited-test prioritization heuristics.
  • Regression tests added for both slash and backslash paths; non-test paths and non-Python files remain ignored.

Why It Matters

Ensures Windows PyTorch contributors get the same test prioritization as Linux/macOS, improving CI reliability.

📬 Get the top 10 AI stories daily