Attribute for consecutive test running

cargo test -- --test-threads=1 can be used to run all tests consecutively. I'd like to label individual tests as being run consecutively, while still letting most tests run in parallel by default. Is there some kind of attribute for doing this, like the following?

#[test(consecutive)]
fn testing() {
  let left = func1();
  let right = 5;
  assert_eq!(left, right);
}

There is no such attribute. You can use some locking mechanism like a Mutex to make sure some tests are run sequentially rather than in parallel though. Or put the tests in different targets as Cargo runs them sequentially, too.

2 Likes

There's a crate for that: serial_test!

2 Likes