问题
I have tests which share a common resource and can't be executed concurrently. These tests fail with cargo test
, but work with RUST_TEST_THREADS=1 cargo test
.
I can modify the tests to wait on a global mutex, but I don't want to clutter them if there is any simpler way to force cargo
set this environment variable for me.
回答1:
As of Rust 1.18, there is no such thing. In fact, there is not even a simpler option to disable parallel testing.
Source
However, what might help you is cargo test -- --test-threads=1
, which is the recommended way of doing what you are doing over the RUST_TEST_THREADS
envvar. Keep in mind that this only sets the number of threads used for testing in addition to the main thread.
来源:https://stackoverflow.com/questions/44947914/how-to-limit-the-number-of-test-threads-in-cargo-toml