如何避免并行运行某些测试? [英] How can I avoid running some tests in parallel?
问题描述
我有一组测试.有一些测试需要访问共享资源(外部库/API/硬件设备).如果这些测试中的任何一个并行运行,它们都会失败.
I have a collection of tests. There are a few tests that need to access a shared resource (external library/API/hardware device). If any of these tests run in parallel, they fail.
我知道我可以使用 --test-threads=1
运行所有东西,但我发现仅用于几个特殊测试不方便.
I know I could run everything using --test-threads=1
but I find that inconvenient just for a couple of special tests.
有什么办法可以让所有测试保持并行运行,并且有一些例外?理想情况下,我想说不要同时运行 X、Y、Z.
Is there any way to keep running all tests in parallel and have an exception for a few? Ideally, I would like to say do not run X, Y, Z at the same time.
推荐答案
使用 serial_test 板条箱.添加此 crate 后,您输入代码:
Use the serial_test crate. With this crate added, you put in your code:
#[serial]
在您要按顺序运行的任何测试之前.
in front of any test you want run in sequentially.
这篇关于如何避免并行运行某些测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!