Disable parallel tests


#1

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


#2

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


#3

For rust 1.1.0, I needed to run

RUST_TEST_THREADS=1 cargo test

http://doc.rust-lang.org/1.1.0/src/test/lib.rs.html#336