la10736 / rstest

Fixture-based test framework for Rust
Apache License 2.0
1.21k stars 43 forks source link

Mixing `#[rstest]` and `#[serial]` breaks VS Code's IntelliSense with rust-analyzer #262

Closed mtilda closed 5 months ago

mtilda commented 5 months ago

Background

I am using the crates rstest and serial_test.

VS Code's IntelliSense stops working when I define a test function with both #[rstest] and #[serial].

IntelliSense is a VS Code feature (or rather a collection of features) that provide suggestions, information about symbols, and navigational tools.

The VS Code extension rust-analyzer provides support for the Rust language.

The root cause of this problem could be any one of the above mentioned technologies. Let me know if you think this issue does not belong on this repository.

Steps to reproduce

  1. Install VS Code (I am on version 1.90.1)

  2. Install the extension rust-analyzer (I am on version v0.3.2002)

  3. Install Rust (I am on 1.78.0)

  4. Use the command cargo init to create a new cargo package.

  5. Add the necessary dependencies with the command cargo add rstest serial_test; or if you want the same versions as me, use the command cargo add rstest@0.21.0 serial_test@3.1.1

  6. Open VS Code

  7. Paste this in src/main.rs:

    mod tests;
    
    fn main() {
        println!("Hello, world!");
    }
  8. Create src/tests.rs with the following content:

    #[cfg(test)]
    mod tests {
        use rstest::rstest;
        use serial_test::serial;
    
        #[rstest]
        fn test_a() {
            // IntelliSense works here
            let _example = vec![1,2,3];
        }
    
        #[test]
        #[serial]
        fn test_b() {
            // IntelliSense works here
            let _example = vec![1,2,3];
        }
    
        #[rstest]
        #[serial]
        fn test_c() {
            // IntelliSense does not work here
            let _example = vec![1,2,3];
        }
    }

Expected behavior

Screenshots

IntelliSense working inside test_a

IntelliSense working inside test_b

IntelliSense not working inside test_c

mtilda commented 5 months ago

Cross-posted: https://github.com/palfrey/serial_test/issues/112#issue-2360631238

la10736 commented 5 months ago

I'm guessing that you posted the issue in the wrong places: It seams more a rust-analyzer issue instead. There's nothing we can do for fix it: from our point of view everything work well:

mdamico@miklap:~/dev_random/rstest_262$ cargo test
   Compiling rstest_262 v0.1.0 (/home/mdamico/dev_random/rstest_262)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.20s
     Running unittests src/main.rs (target/debug/deps/rstest_262-1caee84ec4ffcd71)

running 3 tests
test tests::test_a ... ok
test tests::test_b ... ok
test tests::test_c ... ok

test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
mtilda commented 5 months ago

@la10736 thanks for the quick reply!

Yesterday, per your suggestion, I opened https://github.com/rust-lang/rust-analyzer/issues/17458

Now fixed by: https://github.com/rust-lang/rust-analyzer/pull/17462