fix(tests): use shutil.which and skip POSIX-only tests on Windows - #42872
fix(tests): use shutil.which and skip POSIX-only tests on Windows#42872suhas-svg wants to merge 1 commit into
Conversation
test_search_hidden_dirs.py crashes at collection time on Windows because
subprocess.run(["which", "rg"]) calls the Unix `which` command, which
does not exist on Windows (FileNotFoundError: [WinError 2]).
Changes:
- Replace subprocess.run(["which", "rg"]) with shutil.which("rg")
for cross-platform ripgrep detection (CONTRIBUTING.md rule NousResearch#2)
- Add pytest.mark.skipif(sys.platform == "win32") to find/grep test
classes since those commands are not available on Windows
All 9 tests now pass on Windows (4 passed, 5 correctly skipped).
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Changes Overview
- Windows compatibility fix for test_search_hidden_dirs.py
- Uses
shutil.whichinstead ofsubprocess.run(["which", ...])for command detection - Skips POSIX-only tests (find, grep) on Windows
Analysis
Correctness
- Clean, focused fix for Windows compatibility
shutil.whichis the idiomatic Python way to check for command availability
Code Quality
- Minimal changes, single-purpose fix
Testing
- Appropriate use of
@pytest.mark.skipiffor platform-specific tests
Reviewed by Hermes Agent
|
Thanks for the focused Windows test-compatibility fix. Current No substantive problems identified. The patch applies to unchanged surrounding test code and is mechanically salvageable. Automated hermes-sweeper review. |
Native Windows 11 verificationVerified on a real Windows 11 Home host, build 26200, Python 3.11.6, from PowerShell. This still applies cleanly and still fixes a live failure on today's Before — current Cherry-pick of After: Why this matters more than one filepytest aborts the entire run on a collection error, so any one of these blocks all ~50k tests on Windows, not just its own module. There were three such blockers:
With this one merged, all three are cleared and One note for anyone re-testing: run it from PowerShell or cmd, not Git Bash. MSYS puts its own POSIX LGTM from native Win11. (Not a formal approve — I'm not a collaborator on this repo.) |
What does this PR do?
test_search_hidden_dirs.pycrashes at collection time on Windows becausesubprocess.run(["which", "rg"])calls the Unixwhichcommand, which does not exist on Windows (FileNotFoundError: [WinError 2]). This prevents the entire test suite from running.This PR replaces the Unix-only
whichwith stdlibshutil.which()(as recommended by CONTRIBUTING.md rule #2) and adds platform skip markers forfind/greptest classes that use other POSIX-only commands.Related Issue
No existing issue — discovered while setting up the dev environment on Windows.
Type of Change
Changes Made
tests/tools/test_search_hidden_dirs.py:import shutilandimport syssubprocess.run(["which", "rg"], capture_output=True).returncode != 0withshutil.which("rg") is None(lines 100, 113)@pytest.mark.skipif(sys.platform == "win32", reason="find is not available on Windows")toTestFindExcludesHiddenDirs@pytest.mark.skipif(sys.platform == "win32", reason="grep is not available on Windows")toTestGrepExcludesHiddenDirsHow to Test
pytest tests/tools/test_search_hidden_dirs.py -v --timeout-method=threadBefore this fix:
ERROR collecting tests/tools/test_search_hidden_dirs.py FileNotFoundError: [WinError 2] The system cannot find the file specified
After this fix:
4 passed, 5 skipped in 0.79s
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/A (no docs changes needed)cli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
============================= test session starts ============================= platform win32 -- Python 3.12.5, pytest-9.0.2 tests/tools/test_search_hidden_dirs.py::TestFindExcludesHiddenDirs::test_find_skips_hub_cache_files SKIPPED tests/tools/test_search_hidden_dirs.py::TestFindExcludesHiddenDirs::test_find_skips_git_internals SKIPPED tests/tools/test_search_hidden_dirs.py::TestFindExcludesHiddenDirs::test_find_still_returns_visible_files SKIPPED tests/tools/test_search_hidden_dirs.py::TestGrepExcludesHiddenDirs::test_grep_skips_hub_cache SKIPPED tests/tools/test_search_hidden_dirs.py::TestGrepExcludesHiddenDirs::test_grep_still_finds_visible_content SKIPPED tests/tools/test_search_hidden_dirs.py::TestRipgrepAlreadyExcludesHidden::test_rg_skips_hub_by_default PASSED tests/tools/test_search_hidden_dirs.py::TestRipgrepAlreadyExcludesHidden::test_rg_finds_visible_content PASSED tests/tools/test_search_hidden_dirs.py::TestIgnoreFileWritten::test_write_index_cache_creates_ignore_file PASSED tests/tools/test_search_hidden_dirs.py::TestIgnoreFileWritten::test_write_index_cache_does_not_overwrite_existing_ignore PASSED ======================== 4 passed, 5 skipped in 0.79s =========================