1

I have several tests:

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn foo() {
        // Must be run sequentially
    }

    #[test]
    fn bar() {
        // Must be run sequentially.
    }

    #[test]
    fn baz() {
        // Can be run in parallel.
    }

    #[test]
    fn qux() {
        // Can be run in parallel.
    }
}

foo() and bar() must be run sequentially, because they might race with themselves or another test not shown.

I can prevent a race condition by only using one thread to test, cargo test -- --test-threads=1. But I don't want to do this because I'd like baz() and qux() to be run in parallel.

I could also place the #[ignore] attribute on foo() and bar(). Call cargo test to invoke baz() and qux() in parallel, then just individually run foo() and bar(), but that is a lot of work.

Is there any way to ensure that foo() and bar() run sequentially, but all other tests run in parallel with a single invocation of cargo test? For reference here are the current attributes.

Lukas Kalbertodt
  • 79,749
  • 26
  • 255
  • 305
HiDefender
  • 2,088
  • 2
  • 14
  • 31

0 Answers0