Repository navigation
Keep python crawl tests off the host's venv - #2055
Mikola Lysenko (mikolalysenko) wants to merge 1 commit into
Conversation
Five python_crawler unit tests went through crawl_all and get_site_packages_paths, which read VIRTUAL_ENV and CONDA_PREFIX from the process. In an activated venv the crawler takes that venv instead of the fixture's .venv, so the tests fail on a clean checkout. CI passes only because no job activates a venv. Split out crawl_all_with and get_site_packages_paths_with, which take the env lookup as a closure like local_site_packages_with already does. The public functions pass the process env as before, so behaviour doesn't change. The five tests pass an empty env. poetry_out_of_tree_virtualenvs_are_discovered_without_a_dot_venv already cleared VIRTUAL_ENV under #[serial]; it now clears CONDA_PREFIX too, which Poetry treats the same way. Refs #1919 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011f9aePBmHCMsHKaD7js5Fu
|
bugbot run Generated by Claude Code |
PR SummaryLow Risk Overview This PR introduces injectable Reviewed by Cursor Bugbot for commit 144d4ab. Configure here. |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 144d4ab. Configure here.
|
Ready for review at
Generated by Claude Code |
Final review briefWhat it does. Python crawler unit tests no longer depend on the host's activated venv or conda env. Risk: low. It touches one file. It is a pure refactor of two methods plus test-only changes. No assertion was changed and no test was removed. Look here
Verified
Changes I made: none. Auto-merge is armed, so approving sends it straight to the merge queue. Generated by Claude Code |
Problem
CI is healthy this run: the merge queue is empty, every merge_group run since 11-09 passed, main's latest push run and today's nightly are green (the nightly's first green since 10-27), and nothing is queued. So this run finishes the last open item from #1919 that #2054 left for a follow-up: python crawler unit tests that pass only because CI never activates a venv.
Reproduced on
origin/main(c09cb0e),cargo test -p socket-patch-core --lib crawlers::python_crawler:VIRTUAL_ENV=<a real venv>test_crawl_all_python,test_crawl_all_not_poisoned_by_body_headers,test_crawl_all_recovers_metadata_less_package,base_copy_behind_a_system_site_venv_is_crawled,venv_copy_hides_the_base_copy_of_the_same_packageCONDA_PREFIX=<a real venv>poetry_out_of_tree_virtualenvs_are_discovered_without_a_dot_venvA contributor working from an activated venv or conda env gets red tests on a clean checkout.
Root cause
PythonCrawler::crawl_allandget_site_packages_pathsbuild their env lookup fromstd::env::var, and an activatedVIRTUAL_ENVbeats the fixture's./.venv. The Poetry test already clearsVIRTUAL_ENVunder#[serial], but notCONDA_PREFIX, whichpoetry_active_prefixtreats the same way.Fix
get_site_packages_paths_with(options, var)andcrawl_all_with(options, var). They take the env lookup as a closure, aslocal_site_packages_withalready does. The public functions pass the process env exactly as before, so behaviour doesn't change._withvariants with ano_envlookup. I injected the env instead of anEnvGuard+#[serial]on purpose: mutating process env while other tests run in parallel is itself a flake source.CONDA_PREFIX.No test is removed and no assertion changed. Each test asserts the same thing on the same fixtures.
Proof
cargo test -p socket-patch-core --lib crawlers::after the change:VIRTUAL_ENV=<venv>CONDA_PREFIX=<venv>VIRTUAL_ENV+CONDA_PREFIX+CONDA_DEFAULT_ENV=xcrawlers::python_crawlerunderVIRTUAL_ENV+CONDA_PREFIX, 20 repeats: 0 failures.cargo clippy --locked -p socket-patch-core --all-features -- -D warnings(CI's clippy) is clean. With--all-targetsthe set of lints per file is identical to main (all pre-existing, in test code).rustfmt --checkpasses on the touched file.The public
crawl_allstays covered byrandomized_site_packages_match_the_async_oracleand the CLI integration suites.Together with #2054 this meets #1919's acceptance criteria for
crawlers::, apart from the twonpm_crawlertests #2054 lists, which need the yarn env threaded throughNpmCrawler.Refs #1919
Generated by Claude Code
Generated by Claude Code