sor*_*rin 3 python pytest pytest-xdist
想象一下,我有test/unit/...哪些可以安全地并行运行,test/functional/...哪些还不能并行运行。
有没有一种简单的方法来说服 pytestfunctional依次运行它们?考虑到我们正在谈论大量测试,因此更改每个测试功能/方法会非常嘈杂。
此时我们使用标记过滤器运行测试,因此我们主要将它们分开运行。不过,我正在寻找一种解决方案,以消除将它们分开运行的需要。
您可以实现自己的调度程序,其作用类似于load或loadscope,具体取决于定义测试的模块。示例:
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)
Run Code Online (Sandbox Code Playgroud)
下面的所有测试test/functional将被分组在同一个节点下functional-tests(因此在同一个工作程序中运行),其余的将像往常一样并行运行。