This repository was archived by the owner on Aug 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
Test with same name in workspace share the same state #87
Copy link
Copy link
Open
Labels
help wantedExtra attention is neededExtra attention is needed
Description
Description
When working on a rust workspace that have test with the same test name it result in the tests sharing the name to also share the same state
Reproduction steps
-
cargo new --lib foo -
cd foo -
cargo new --lib bar -
Patch cargo config to include
barpkg as workspace member:diff --git a/Cargo.lock b/Cargo.lock index b1ddcd9..8bcef45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,10 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "bar" +version = "0.1.0" + [[package]] name = "foo" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 0512608..fc1de9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,7 @@ name = "foo" version = "0.1.0" edition = "2024" +[workspace] +members = ["bar"] + [dependencies]
-
Patch
barpkg to have a failing test:diff --git a/bar/src/lib.rs b/bar/src/lib.rs index b93cf3f..5120f2f 100644 --- a/bar/src/lib.rs +++ b/bar/src/lib.rs @@ -9,6 +9,6 @@ mod tests { #[test] fn it_works() { let result = add(2, 2); - assert_eq!(result, 4); + assert_eq!(result, 5); } }
-
Confirm that one test fail (of 2) in the workspace with
cargo test --workspace --no-fail-fast --tests:running 1 test test tests::it_works ... FAILED failures: ---- tests::it_works stdout ---- thread 'tests::it_works' panicked at bar/src/lib.rs:12:9: assertion `left == right` failed left: 4 right: 5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace failures: tests::it_works test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s running 1 test test tests::it_works ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s -
Now open
neovimand run one of the test withneotestyou will see that the other test will have the same state as the runned test.
Metadata
Metadata
Assignees
Labels
help wantedExtra attention is neededExtra attention is needed