# Disable parallel tests

**URL:** <https://internals.rust-lang.org/t/disable-parallel-tests/1592>\
**Category:** Uncategorized\
**Created:** [February 14, 2015, 5:04pm UTC](https://internals.rust-lang.org/t/disable-parallel-tests/1592 "2015-02-14T17:04:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![galsondor](https://avatars.discourse-cdn.com/v4/letter/g/e99b99/32.png) [@galsondor](https://internals.rust-lang.org/u/galsondor)\
**Post date:** [February 14, 2015, 5:04pm UTC](https://internals.rust-lang.org/t/disable-parallel-tests/1592/1 "2015-02-14T17:04:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![steveklabnik](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steveklabnik/32/4524_2.png) [@steveklabnik](https://internals.rust-lang.org/u/steveklabnik)\
**Post date:** [February 14, 2015, 5:16pm UTC](https://internals.rust-lang.org/t/disable-parallel-tests/1592/2 "2015-02-14T17:16:22Z")

</div>

RUST\_TEST\_TASKS=1 will make you only have one thread, and therefore, tests will be executed serially.

---

<div class="post-metadata">

**Author:** ![hnakamur](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/hnakamur/32/1123_2.png) [@hnakamur](https://internals.rust-lang.org/u/hnakamur)\
**Post date:** [July 20, 2015, 2:03pm UTC](https://internals.rust-lang.org/t/disable-parallel-tests/1592/3 "2015-07-20T14:03:06Z")

</div>

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](http://doc.rust-lang.org/1.1.0/src/test/lib.rs.html#336)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:23am UTC](https://internals.rust-lang.org/t/disable-parallel-tests/1592/4 "2019-03-25T08:23:55Z")

</div>

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