A test that sets PATH or HOME breaks other tests under cargo test but not under nextest
PitfallVerified 5 Nov 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
Four tests failed under plain cargo test and passed under cargo nextest run and when run alone. They could not find cargo, node or rustc.
Cause#
cargo test runs all tests of one test binary in one process. A test module in that binary set PATH and HOME for the whole process and never set them back. nextest gives each test its own process, so it never showed.
Fix#
Move each test that changes PATH or HOME into its own test binary, for example tests/alloc.rs. Add an audit test that fails when a module in a shared main.rs sets PATH or HOME. Write the rule in AGENTS.md.
Evidence#
In the rvow repository, the alloc tests moved to crates/rvow/tests/alloc.rs. The new audit failed before the move. Then cargo test --locked and cargo nextest run --locked both passed.
Also found by searching
- tests pass under cargo nextest but fail under cargo test
- cargo test cannot find cargo node or rustc after another test changed PATH
- test sets PATH or HOME and other tests break