-
Notifications
You must be signed in to change notification settings - Fork 52.8k
fix(test): support Windows virtualenvs in canonical runner #63642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
lucamoretti09
wants to merge
1
commit into
NousResearch:main
from
lucamoretti09:contrib/windows-test-runner
+39
−8
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[2] | ||
| RUNNER = REPO_ROOT / "scripts" / "run_tests.sh" | ||
|
|
||
|
|
||
| def test_runner_supports_posix_and_windows_virtualenv_layouts(): | ||
| script = RUNNER.read_text(encoding="utf-8") | ||
|
|
||
| assert 'if [ -f "$candidate/bin/activate" ]' in script | ||
| assert 'PYTHON="$candidate/bin/python"' in script | ||
| assert 'if [ -f "$candidate/Scripts/python.exe" ]' in script | ||
| assert 'PYTHON="$candidate/Scripts/python.exe"' in script | ||
| assert 'PYTHON="$VENV/bin/python"' not in script | ||
|
|
||
|
|
||
| def test_runner_preserves_windows_home_and_utf8_in_clean_environment(): | ||
| script = RUNNER.read_text(encoding="utf-8") | ||
|
|
||
| assert 'USERPROFILE="${USERPROFILE:-$HOME}"' in script | ||
| assert "PYTHONUTF8=1" in script | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -784,8 +784,9 @@ diagnostic recipe in `references/execute-code-sandbox-env-windows.md`. | |
|
|
||
| ### Testing / Contributing | ||
|
|
||
| **`scripts/run_tests.sh` doesn't work as-is on Windows** — it looks for | ||
| POSIX venv layouts (`.venv/bin/activate`). The Hermes-installed venv at | ||
| **`scripts/run_tests.sh` supports native Windows venv layouts** — it probes | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This page is generated from |
||
| both POSIX (`.venv/bin/python`) and Windows (`.venv/Scripts/python.exe`) | ||
| interpreters. The Hermes-installed venv at | ||
| `venv/Scripts/` has no pip or pytest either (stripped for install size). | ||
| Workaround: install `pytest + pytest-xdist + pyyaml` into a system Python | ||
| 3.11 user site, then invoke pytest directly with `PYTHONPATH` set: | ||
|
|
@@ -1004,14 +1005,15 @@ python -m pytest tests/tools/ -q # Specific area | |
| - Run full suite before pushing any change | ||
| - Use `-o 'addopts='` to clear any baked-in pytest flags | ||
|
|
||
| **Windows contributors:** `scripts/run_tests.sh` currently looks for POSIX venvs (`.venv/bin/activate` / `venv/bin/activate`) and will error out on Windows where the layout is `venv/Scripts/activate` + `python.exe`. The Hermes-installed venv at `venv/Scripts/` also has no `pip` or `pytest` — it's stripped for end-user install size. Workaround: install pytest + pytest-xdist + pyyaml into a system Python 3.11 user site (`/c/Program Files/Python311/python -m pip install --user pytest pytest-xdist pyyaml`), then run tests directly: | ||
| **Windows contributors:** `scripts/run_tests.sh` recognizes `venv/Scripts/python.exe` and preserves `USERPROFILE` plus UTF-8 mode in its clean environment. The Hermes-installed end-user venv may still omit `pip` or `pytest` to reduce install size; use a development venv with the test dependencies installed. | ||
|
|
||
| ```bash | ||
| export PYTHONPATH="$(pwd)" | ||
| "/c/Program Files/Python311/python" -m pytest tests/tools/test_foo.py -v --tb=short -n 0 | ||
| ``` | ||
|
|
||
| Use `-n 0` (not `-n 4`) because `pyproject.toml`'s default `addopts` already includes `-n`, and the wrapper's CI-parity story doesn't apply off-POSIX. | ||
| When invoking pytest directly, use `-n 0` (not `-n 4`) because | ||
| `pyproject.toml`'s default `addopts` already includes `-n`. | ||
|
|
||
| **Cross-platform test guards:** tests that use POSIX-only syscalls need a skip marker. Common ones already in the codebase: | ||
| - Symlink creation → `@pytest.mark.skipif(sys.platform == "win32", reason="Symlinks require elevated privileges on Windows")` (see `tests/cron/test_cron_script.py`) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test snapshots shell source rather than executing behavior, which
AGENTS.md:1358-1411bans. Please replace it with a behavioral invocation against a temporary fixture/venv so it proves the selected interpreter and clean environment work.