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;
    #[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).

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

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

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.