Skip to content

fix(ci): make pytest deps importable in Bazel venv on Linux#2657

Open
benfdking wants to merge 2 commits into
mainfrom
fix/bazel-pytest-pythonpath
Open

fix(ci): make pytest deps importable in Bazel venv on Linux#2657
benfdking wants to merge 2 commits into
mainfrom
fix/bazel-pytest-pythonpath

Conversation

@benfdking
Copy link
Copy Markdown
Collaborator

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:

//:pytest_py310  FAILED
//:pytest_py311  FAILED
//:pytest_py312  FAILED
//:pytest_py313  FAILED
  → pytest_py3XX_venv_venv/bin/python3: No module named pytest

...even though the venv-sync step right above logs + pytest==9.0.3 as installed. Because it's independent of the diff, PRs have been merging with a red Bazel Lint check.

Root cause

uv_python_venv (in cargo_build.bzl) installs deps into the standalone interpreter's sysconfig purelib via uv pip install --prefix. Relocated standalone Python builds on Linux don't auto-add that purelib to sys.path, so python3 -m pytest can't import pytest. macOS auto-discovers it, which is why the targets pass locally but fail on ubuntu-latest.

Fix

In .hacking/scripts/pytest_uv.sh, resolve purelib from the interpreter itself (sysconfig.get_path("purelib")) and prepend it to PYTHONPATH before 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_py313 still passes locally; the Linux behavior is verified by this PR's CI run.

🤖 Generated with Claude Code

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>
@github-actions
Copy link
Copy Markdown
Contributor

Benchmark for 19ce05f

Click to view benchmark
Test Base PR %
DepthMap::from_parent 61.7±0.47µs 61.5±0.30µs -0.32%
fix_complex_query 12.8±0.11ms 13.2±0.09ms +3.13%
fix_superlong 177.5±8.10ms 181.7±7.58ms +2.37%
parse_complex_query 4.3±0.06µs 4.2±0.02µs -2.33%
parse_expression_recursion 7.5±0.05µs 7.3±0.10µs -2.67%
parse_simple_query 1085.0±6.15ns 1057.5±9.15ns -2.53%

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>
@github-actions
Copy link
Copy Markdown
Contributor

Benchmark for 01acbcd

Click to view benchmark
Test Base PR %
DepthMap::from_parent 61.4±0.67µs 61.0±0.62µs -0.65%
fix_complex_query 12.8±0.11ms 12.7±0.06ms -0.78%
fix_superlong 172.3±3.03ms 173.9±4.96ms +0.93%
parse_complex_query 4.2±0.02µs 4.2±0.02µs 0.00%
parse_expression_recursion 7.1±0.03µs 7.4±0.04µs +4.23%
parse_simple_query 1076.1±15.55ns 1083.5±5.92ns +0.69%

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Jun 1, 2026

Merging this PR will not alter performance

✅ 6 untouched benchmarks
⏩ 6 skipped benchmarks1


Comparing fix/bazel-pytest-pythonpath (1a7ab01) with main (db085d7)

Open in CodSpeed

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant