Disable parallel tests


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;
    fn var_returns_ok_for_existing_envvnar() {
        env::set_var("XXXX", "xxxx");
    fn var_returns_err_for_missing_envvnar() {

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).


RUST_TEST_TASKS=1 will make you only have one thread, and therefore, tests will be executed serially.


For rust 1.1.0, I needed to run

RUST_TEST_THREADS=1 cargo test