Search code examples
rustrust-cargo

How can I avoid running some tests in parallel?


I have a collection of tests. There are a few tests that need to access a shared resource (external library/API/hardware device). If any of these tests run in parallel, they fail.

I know I could run everything using --test-threads=1 but I find that inconvenient just for a couple of special tests.

Is there any way to keep running all tests in parallel and have an exception for a few? Ideally, I would like to say do not run X, Y, Z at the same time.


Solution

  • Use the serial_test crate. With this crate added, you put in your code:

    #[serial]
    

    in front of any test you want run in sequentially.