Add a Scheduling Protocol

- Clearly delineate the required interface of schedulers
- Useful for typing
This commit is contained in:
Ran Benita
2024-04-05 14:38:21 +03:00
parent 91812bf5f9
commit bf2dcccfb0
6 changed files with 72 additions and 10 deletions

View File

@@ -15,6 +15,7 @@ from xdist.scheduler import LoadFileScheduling
from xdist.scheduler import LoadGroupScheduling
from xdist.scheduler import LoadScheduling
from xdist.scheduler import LoadScopeScheduling
from xdist.scheduler import Scheduling
from xdist.scheduler import WorkStealingScheduling
from xdist.workermanage import NodeManager
@@ -97,17 +98,21 @@ class DSession:
return True
@pytest.hookimpl(trylast=True)
def pytest_xdist_make_scheduler(self, config, log):
def pytest_xdist_make_scheduler(self, config, log) -> Scheduling | None:
dist = config.getvalue("dist")
schedulers = {
"each": EachScheduling,
"load": LoadScheduling,
"loadscope": LoadScopeScheduling,
"loadfile": LoadFileScheduling,
"loadgroup": LoadGroupScheduling,
"worksteal": WorkStealingScheduling,
}
return schedulers[dist](config, log)
if dist == "each":
return EachScheduling(config, log)
if dist == "load":
return LoadScheduling(config, log)
if dist == "loadscope":
return LoadScopeScheduling(config, log)
if dist == "loadfile":
return LoadFileScheduling(config, log)
if dist == "loadgroup":
return LoadGroupScheduling(config, log)
if dist == "worksteal":
return WorkStealingScheduling(config, log)
return None
@pytest.hookimpl
def pytest_runtestloop(self):