cargo "test failed, to rerun pass --lib" in CI
A test assertion failed or a test panicked. cargo prints the failing test names, a FAILED summary, and "error: test failed, to rerun pass --lib" so you can re-run just that binary. The real cause is in the panic output above.
What this error means
cargo test ends with a "test result: FAILED" line, the names of failing tests, and "error: test failed, to rerun pass --lib" (or --bin X, --test Y).
running 2 tests
test math::tests::it_adds ... FAILED
failures:
---- math::tests::it_adds stdout ----
thread 'math::tests::it_adds' panicked at src/math.rs:21:9:
assertion `left == right` failed
left: 4
right: 5
error: test failed, to rerun pass `--lib`Common causes
A failing assertion or panic in a test
The test body asserted something false or hit a panic; the captured stdout shows the assertion and source location.
A test that depends on environment or ordering
Tests that read the clock, locale, network, or shared state can pass locally but fail under CI's different environment or parallelism.
How to fix it
Rerun the failing target and read the panic
- Use the exact rerun hint cargo printed (
--lib,--bin,--test). - Read the panic message and source span in the captured stdout.
- Fix the assertion or the code it exercises.
cargo test --lib math::tests::it_adds -- --exact --nocaptureRemove environment and ordering coupling
Isolate per-test state, inject time and locale, and avoid relying on test execution order so CI and local agree.
RUST_TEST_THREADS=1 cargo testHow to prevent it
- Run the full test suite locally before pushing.
- Isolate state and inject time/locale so tests are deterministic.
- Use the printed rerun hint to focus on the failing target.