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

#[serial] macro for modules #103

Closed
xamgore opened this issue Dec 30, 2023 · 12 comments · Fixed by #104
Closed

#[serial] macro for modules #103

xamgore opened this issue Dec 30, 2023 · 12 comments · Fixed by #104

Comments

@xamgore
Copy link

xamgore commented Dec 30, 2023

It's kind of tedious to mark each test function with a macros. Is there a way to make all of the functions inside mod tests { ... } serial?

@palfrey
Copy link
Owner

palfrey commented Dec 30, 2023

TBH, mostly because no-one asked for this before! This looks certainly doable. It'd basically apply the same set of options (serial/parallel, etc and the relevant set keys) to all the #[test]-marked functions inside a block. Let me have a prod...

@palfrey
Copy link
Owner

palfrey commented Dec 30, 2023

@xamgore #104 should do this. Can you test it with your use case please?

@xamgore
Copy link
Author

xamgore commented Jan 8, 2024

I got ill on the weekends, does it still need testing?

@palfrey
Copy link
Owner

palfrey commented Jan 8, 2024

The 3.0.0 release has gone out with this in, if you can test that against your use case?

@ririsoft
Copy link

@palfrey: the mod level #[serial] does not seem to work with tokio tests, am I doing it wrong ?

#[cfg(test)]
#[serial_test::serial]
mod tests {

    #[tokio::test]
    async fn foo()  {
       println!("foo test");
    }

    #[tokio::test]
    async fn bar()  {
       println!("bar test");
    }

}

@palfrey
Copy link
Owner

palfrey commented Apr 21, 2024

@palfrey: the mod level #[serial] does not seem to work with tokio tests, am I doing it wrong ?

#[cfg(test)]
#[serial_test::serial]
mod tests {

    #[tokio::test]
    async fn foo()  {
       println!("foo test");
    }

    #[tokio::test]
    async fn bar()  {
       println!("bar test");
    }

}

No, you're not. I made some assumptions about test ident names that weren't actually tested, and only regular tests get matched, not tokio::test or any other <foo>::test. Looking at that now.

@palfrey
Copy link
Owner

palfrey commented Apr 21, 2024

#110

@palfrey
Copy link
Owner

palfrey commented Apr 21, 2024

@ririsoft
Copy link

Thanks @palfrey for all the effort, it is much appreciated.
I am still having an issue. I get the error

message: called `Result::unwrap()` on an `Err` value: Error("unexpected token")

with the following code:

#[cfg(test)]
#[serial_test::serial]
mod tests {

    #[tokio::test]
    #[ignore = "blabla"]
    async fn foo() -> Result<(), ()> {
        Ok(())
    }

    #[tokio::test]
    async fn bar() -> Result<(), ()> {
      Ok(())
    }

}

@palfrey
Copy link
Owner

palfrey commented Apr 27, 2024

#111 - I'd fixed blah::test attributes, but not async ones!

@palfrey
Copy link
Owner

palfrey commented Apr 27, 2024

@ririsoft
Copy link

ririsoft commented May 1, 2024

@palfrey : it works for me, thank you !

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

Successfully merging a pull request may close this issue.

3 participants