Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.
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

@FirelightFlagboy

Description

@FirelightFlagboy

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

  1. cargo new --lib foo

  2. cd foo

  3. cargo new --lib bar

  4. Patch cargo config to include bar pkg 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]
  5. Patch bar pkg 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);
         }
     }
  6. 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
  7. Now open neovim and run one of the test with neotest you will see that the other test will have the same state as the runned test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions