fix(ci): make pytest deps importable in Bazel venv on Linux#2657
Open
benfdking wants to merge 2 commits into
Open
fix(ci): make pytest deps importable in Bazel venv on Linux#2657benfdking wants to merge 2 commits into
benfdking wants to merge 2 commits into
Conversation
The hermetic pytest targets (//:pytest_py310..313) failed on every PR with "No module named pytest", even though uv reported installing it. Dependencies are installed into the standalone interpreter's sysconfig purelib via `uv pip install --prefix`, but relocated standalone Python builds on Linux don't auto-add that directory to sys.path, so the import failed. macOS auto-discovers it, which is why it passed locally. Resolve purelib from the interpreter itself and put it on PYTHONPATH before running pytest, so installed deps import consistently across platforms. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Benchmark for 19ce05fClick to view benchmark
|
The sysconfig.get_path("purelib") approach still failed on Linux, meaning
uv installed the packages somewhere other than the interpreter's runtime
purelib. Instead, find the site-packages/dist-packages dirs directly and
put them all on PYTHONPATH, plus emit diagnostics if pytest still isn't
importable so we can see the actual Linux layout.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
Benchmark for 01acbcdClick to view benchmark
|
Merging this PR will not alter performance
Comparing Footnotes
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The Bazel Lint job has been failing on essentially every PR. The failure isn't the PR code — the Rust build/tests pass, but the hermetic Python test targets fail uniformly:
...even though the venv-sync step right above logs
+ pytest==9.0.3as installed. Because it's independent of the diff, PRs have been merging with a red Bazel Lint check.Root cause
uv_python_venv(incargo_build.bzl) installs deps into the standalone interpreter's sysconfig purelib viauv pip install --prefix. Relocated standalone Python builds on Linux don't auto-add that purelib tosys.path, sopython3 -m pytestcan't import pytest. macOS auto-discovers it, which is why the targets pass locally but fail onubuntu-latest.Fix
In
.hacking/scripts/pytest_uv.sh, resolve purelib from the interpreter itself (sysconfig.get_path("purelib")) and prepend it toPYTHONPATHbefore invoking pytest. This is exactly where uv installed the packages, so imports resolve deterministically on all platforms. No-op on macOS (already on the path).Verified
bazelisk test --config=ci //:pytest_py313still passes locally; the Linux behavior is verified by this PR's CI run.🤖 Generated with Claude Code