Is there any way to disable running tests in parallel? Sometimes this will simplify development of tests that need access to the same shared resources. Here is a very simple example using the test process’s environment:
mod test {
use std::env;
#[test]
fn var_returns_ok_for_existing_envvnar() {
env::set_var("XXXX", "xxxx");
assert!(env::var("XXXX").is_ok());
}
#[test]
fn var_returns_err_for_missing_envvnar() {
env::remove_var("XXXX");
assert!(env::var("XXXX").is_err());
}
}
If cargo test
is run enough times, occasional failures will be observed even though the code is correct. Of course in the case of environment variables, different environment variable names can easily be used. In a more complex scenario, the shared resource might not be so easily sharable (e.g., hardware).