如何告诉 pytest-xdist 依次从一个文件夹运行测试,其余的并行运行? [英] How to tell pytest-xdist to run tests from one folder sequencially and the rest in parallel?
问题描述
想象一下,我有 test/unit/...
可以安全地并行运行,而 test/functional/...
还不能并行运行.
Imagine that I have test/unit/...
which are safe to run in parallel and test/functional/...
which cannot be run in parallel yet.
是否有一种简单的方法可以说服 pytest 依次运行 functional
?考虑到我们正在讨论大量测试,因此更改每个测试函数/方法会非常嘈杂.
Is there an easy way to convince pytest to run the functional
ones sequentially? Consider that we are talking about a big number of tests so altering each test function/method would be very noisy.
此时我们使用标记过滤器运行测试,因此我们主要将它们分开运行.不过,我正在寻找一种解决方案,以消除将它们分开运行的需要.
At this moment we run tests with marker filters so mainly we run them separated. Still, I am looking for a solution for removing the need to run them separated.
推荐答案
您可以实现自己的调度程序,其作用类似于 load
或 loadscope
,具体取决于测试的模块定义在.示例:
You can implement your own scheduler that acts like load
or loadscope
, depending on what module the test is defined in. Example:
from xdist.scheduler.loadscope import LoadScopeScheduling
class MyScheduler(LoadScopeScheduling):
def _split_scope(self, nodeid):
if 'test/functional' in nodeid:
return 'functional-tests'
return nodeid
def pytest_xdist_make_scheduler(config, log):
return MyScheduler(config, log)
test/functional
下的所有测试将被分组在同一个节点 functional-tests
下(因此在同一个 worker 中运行),其余的将并行运行像往常一样.
All tests under test/functional
will be grouped under the same node functional-tests
(and thus run in the same worker), the rest will be run in parallel as usual.
这篇关于如何告诉 pytest-xdist 依次从一个文件夹运行测试,其余的并行运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!