1414
1515from xdist .remote import Producer
1616from xdist .remote import WorkerInfo
17- from xdist .scheduler import EachScheduling
18- from xdist .scheduler import LoadFileScheduling
19- from xdist .scheduler import LoadGroupScheduling
20- from xdist .scheduler import LoadScheduling
21- from xdist .scheduler import LoadScopeScheduling
2217from xdist .scheduler import Scheduling
23- from xdist .scheduler import WorkStealingScheduling
2418from xdist .workermanage import NodeManager
2519from xdist .workermanage import WorkerController
2620
@@ -81,11 +75,18 @@ def report_line(self, line: str) -> None:
8175
8276 @pytest .hookimpl (trylast = True )
8377 def pytest_sessionstart (self , session : pytest .Session ) -> None :
84- """Creates and starts the nodes.
78+ """Initializes the scheduler, creates and starts the nodes.
8579
8680 The nodes are setup to put their events onto self.queue. As
8781 soon as nodes start they will emit the worker_workerready event.
8882 """
83+ self .sched = self .config .hook .pytest_xdist_make_scheduler (
84+ config = self .config , log = self .log
85+ )
86+ if self .sched is None :
87+ dist = self .config .getoption ("dist" )
88+ raise pytest .UsageError (f"pytest-xdist: scheduler { dist !r} not found" )
89+
8990 self .nodemanager = NodeManager (self .config )
9091 nodes = self .nodemanager .setup_nodes (putevent = self .queue .put )
9192 self ._active_nodes .update (nodes )
@@ -104,34 +105,8 @@ def pytest_collection(self) -> bool:
104105 # prohibit collection of test items in controller process
105106 return True
106107
107- @pytest .hookimpl (trylast = True )
108- def pytest_xdist_make_scheduler (
109- self ,
110- config : pytest .Config ,
111- log : Producer ,
112- ) -> Scheduling | None :
113- dist = config .getvalue ("dist" )
114- if dist == "each" :
115- return EachScheduling (config , log )
116- if dist == "load" :
117- return LoadScheduling (config , log )
118- if dist == "loadscope" :
119- return LoadScopeScheduling (config , log )
120- if dist == "loadfile" :
121- return LoadFileScheduling (config , log )
122- if dist == "loadgroup" :
123- return LoadGroupScheduling (config , log )
124- if dist == "worksteal" :
125- return WorkStealingScheduling (config , log )
126- return None
127-
128108 @pytest .hookimpl
129109 def pytest_runtestloop (self ) -> bool :
130- self .sched = self .config .hook .pytest_xdist_make_scheduler (
131- config = self .config , log = self .log
132- )
133- assert self .sched is not None
134-
135110 self .shouldstop = False
136111 pending_exception = None
137112 while not self .session_finished :
0 commit comments