Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Actions Not Working With Async Tests #156

Closed
LuisOsta opened this issue Jul 7, 2022 · 3 comments
Closed

Code Actions Not Working With Async Tests #156

LuisOsta opened this issue Jul 7, 2022 · 3 comments

Comments

@LuisOsta
Copy link

LuisOsta commented Jul 7, 2022

This is what the top line of the test looks like.

 #[rstest::rstest]
    #[case::network_failure(
        create_did(),
        create_did_doc(create_did()),
        Some(Err(tonic::Status::invalid_argument("message"))),
        false
    )]
    #[case::success(
        create_did(),
        create_did_doc(create_did()),
        Some(Ok(tonic::Response::new(CreateResponse {}))),
        true
    )]
    #[case::parsing_failure(
        create_did(),
        serde_json::json!("{}"),
        None,
        false
    )]
    async fn test_create(
        #[case] did: String,
        #[case] doc: serde_json::Value,
        #[case] mock_create_response: Option<
            Result<tonic::Response<CreateResponse>, tonic::Status>,
        >,
        #[case] expect_ok: bool,
    )

Whenever we remove the async prefix to the function we have the code actions that allow us to run a specific test case. But once its async we don't have that option

@la10736
Copy link
Owner

la10736 commented Jul 7, 2022

What do you mean with code action? Are you speaking about something like gutter icon on vscode or other IDE feature?

@LuisOsta
Copy link
Author

@la10736 I mean the code actions provided by the rust-analyzer vscode extension. It just seemed curious to me that it didn't work for async tests and thought it was an issue with rstest. As it didn't display the case by case and thought that the issue was with what the rstest macro handled the async test cases:

I've attached a photo of what it looks like normally vs async:

Normal
Screen Shot 2022-07-13 at 9 21 09 AM

Async
Screen Shot 2022-07-13 at 9 21 09 AM

Both tests are structured in the exact same way. The only difference is the usage of async testing as described here - https://docs.rs/rstest/latest/rstest/attr.rstest.html#async

@la10736
Copy link
Owner

la10736 commented Jul 14, 2022

Hi, you posted the same image twice :)

Anyway, that is (eventually) a rust-analyzer vscode extension's bug. I've already looked on a closed topic #120.

I guess that vscode just looking for #[test] attribute but for async tests we use #[async_std::test] attribute instead. I think that the best approach is to search an attribute where the last path segment is test but that is a vscode's chose ... not mine.

@la10736 la10736 closed this as completed Oct 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants