vscode-rust icon indicating copy to clipboard operation
vscode-rust copied to clipboard

tokio:test is not recognized as a test

Open jafhueppe opened this issue 5 years ago • 5 comments

Hey there,

I'm writing a rust program which uses tokio for async functions. I wrote some tests for these async functions and need to annotate them with #[tokio:test] instead of #[test]. Because it's another annotation, the extension doesn't recognize it as a test, so the "Run test" text is missing.

Is it possible to add this annotation? It's pretty handy to run only a singe test with this clickable text

Minimal example

#[tokio:test]
async fn test_example() {
  let body = reqwest::get("https://www.rust-lang.org")
      .await?
      .text()
      .await?;

  println!("body = {:?}", body);
}

jafhueppe avatar Apr 03 '20 07:04 jafhueppe

I've got exactly the same problem, only with actix_rt:test instead.

What may be best is to be able to configure which attributes are recognised so that people can add their own as needed.

sazzer avatar Apr 24 '20 15:04 sazzer

I switched to rust-analyzer.. It's faster and support other test macros. Mayber you @sazzer can give it a try as well :)

jafhueppe avatar Apr 29 '20 17:04 jafhueppe

Same problem with tokio 1.20.1 and rust 1.63. I'm using rust-analyzer

ccddan avatar Aug 16 '22 05:08 ccddan

Fixed.

Initially I just added tokio to my Cargo file as tokio = "^1.20". The correct way to add the dependency for my tests was tokio = { version = "^1.20", features = ["rt-multi-thread", "macros"] }.

If you are going to use more tokio feature, you can use {..., features = ["full"]} instead.

ccddan avatar Aug 16 '22 05:08 ccddan

@ccddan consider filing rust-analyzer issues in its own repo.

If you still have trouble with attribute proc macros, you can use rust-analyzer.procMacro.ignored to ignore them.

lnicola avatar Aug 16 '22 05:08 lnicola