How to configure tests in Cargo.toml (test-threads=1)

Right now the way my tests are written they won't work well using threads so I'd like to make sure the tests always run in a single thread.

On the command line this works:

cargo test -- --test-threads=1

Is there a way to put the --test-threads=1 part in Cargo.toml (or some other configuration file) so I won't have to type the whole command and other who might clone the project won't run the tests by mistake with threads?

I like @vague's answer from a year ago concerning how you can set test-threads other than via the CLI:

This answer from the same topic is also neat:

(Really, you should probably read the whole topic as the discussion in it about whether you even should run your test harness single threaded or not is also quite nice)


It's probably better to wrap the sensitive tests into a shared mutex so that those that aren't sensitive can still run in parallel. Otherwise you're slowing down the entire testsuite for just those that have an issue.

1 Like