49
49
import random
50
50
from typing import TYPE_CHECKING
51
51
52
- from _pytest .runner import CollectReport
53
52
import pytest
54
53
55
54
from xdist .report import report_collection_diff
@@ -142,7 +141,7 @@ def __init__(self, config: pytest.Config, log: xdist.remote.Producer):
142
141
# is performed once the number of registered node collections reaches
143
142
# `_expected_num_workers`. It is initialized to None and then updated
144
143
# after validation succeeds.
145
- self ._official_test_collection : tuple [str ] | None = None
144
+ self ._official_test_collection : tuple [str , ... ] | None = None
146
145
# Remote worker node having `_official_test_collection` as its test
147
146
# collection (for reporting failed collection validations)
148
147
self ._official_test_collection_node : WorkerController | None = None
@@ -367,7 +366,7 @@ def add_node_collection(
367
366
368
367
# Check that the new collection matches the official collection
369
368
if self ._do_two_nodes_have_same_collection (
370
- reference_node = self ._official_test_collection_node ,
369
+ reference_node = self ._official_test_collection_node , # type: ignore[arg-type]
371
370
reference_collection = self ._official_test_collection ,
372
371
node = node ,
373
372
collection = collection ,
@@ -528,7 +527,7 @@ def _reschedule_workers(self) -> None:
528
527
"""Distribute work to workers if needed at this time."""
529
528
assert self ._state is not None
530
529
531
- traversed_states = []
530
+ traversed_states : list [ IsoScopeScheduling . _State ] = []
532
531
previous_state = None
533
532
while self ._state != previous_state :
534
533
# NOTE: This loop will terminate because completion of tests and
@@ -815,12 +814,11 @@ def _distribute_workset(
815
814
)
816
815
817
816
num_tests_remaining = workset .high_water
817
+ worker : _WorkerProxy
818
+ num_available_workers : int
818
819
for worker , num_available_workers in zip (
819
820
workers , range (num_workers_to_use , 0 , - 1 )
820
821
):
821
- worker : _WorkerProxy
822
- num_available_workers : int
823
-
824
822
# Workers ready for distribution must have no more than one pending
825
823
# test
826
824
assert (
@@ -1021,7 +1019,7 @@ def _get_workers_ready_for_fencing(self, scope_id: str) -> list[_WorkerProxy]:
1021
1019
def _do_two_nodes_have_same_collection (
1022
1020
self ,
1023
1021
reference_node : WorkerController ,
1024
- reference_collection : tuple [str ],
1022
+ reference_collection : tuple [str , ... ],
1025
1023
node : WorkerController ,
1026
1024
collection : tuple [str , ...],
1027
1025
) -> bool :
@@ -1050,7 +1048,7 @@ def _do_two_nodes_have_same_collection(
1050
1048
# NOTE: Not sure why/when `_config` would be `None`. Copied check
1051
1049
# from the `loadscope` scheduler.
1052
1050
1053
- report = CollectReport (node .gateway .id , "failed" , longrepr = msg , result = [])
1051
+ report = pytest . CollectReport (node .gateway .id , "failed" , longrepr = msg , result = [])
1054
1052
self ._config .hook .pytest_collectreport (report = report )
1055
1053
1056
1054
return False
@@ -1072,11 +1070,11 @@ def __init__(self, node: WorkerController):
1072
1070
1073
1071
# An ordered collection of test IDs collected by the remote worker.
1074
1072
# Initially None, until assigned by the Scheduler
1075
- self ._collection : tuple [str ] | None = None
1073
+ self ._collection : tuple [str , ... ] | None = None
1076
1074
1077
1075
self ._pending_test_by_index : OrderedDict [int , _TestProxy ] = OrderedDict ()
1078
1076
1079
- def __repr__ (self ):
1077
+ def __repr__ (self ) -> str :
1080
1078
return self .verbose_repr (verbose = False )
1081
1079
1082
1080
@property
@@ -1085,15 +1083,15 @@ def node(self) -> WorkerController:
1085
1083
return self ._node
1086
1084
1087
1085
@property
1088
- def collection (self ) -> tuple [str ] | None :
1086
+ def collection (self ) -> tuple [str , ... ] | None :
1089
1087
"""
1090
1088
:return: An ordered collection of test IDs collected by the remote
1091
1089
worker; `None` if the collection is not available yet.
1092
1090
"""
1093
1091
return self ._collection
1094
1092
1095
1093
@collection .setter
1096
- def collection (self , collection : tuple [str ]):
1094
+ def collection (self , collection : tuple [str , ... ]):
1097
1095
"""
1098
1096
:param collection: An ordered collection of test IDs collected by the
1099
1097
remote worker. Must not be `None`. Also, MUST NOT be set already.
@@ -1243,7 +1241,7 @@ def __init__(self, test_id: str, test_index: int):
1243
1241
self .test_id : str = test_id
1244
1242
self .test_index : int = test_index
1245
1243
1246
- def __repr__ (self ):
1244
+ def __repr__ (self ) -> str :
1247
1245
return (
1248
1246
f"<{ self .__class__ .__name__ } : test_index={ self .test_index } "
1249
1247
f"scope_id={ self .scope_id } test_id={ self .test_id } >"
@@ -1273,7 +1271,7 @@ def __init__(self, scope_id: str):
1273
1271
1274
1272
self ._test_by_index : OrderedDict [int , _TestProxy ] = OrderedDict ()
1275
1273
1276
- def __repr__ (self ):
1274
+ def __repr__ (self ) -> str :
1277
1275
return (
1278
1276
f"<{ self .__class__ .__name__ } : scope_id={ self .scope_id } "
1279
1277
f"num_tests={ self .num_tests } high_water={ self .high_water } >"
@@ -1333,10 +1331,10 @@ def dequeue_tests(self, num_tests: int) -> list[_TestProxy]:
1333
1331
class _WorksetQueue :
1334
1332
"""Ordered collection of Scope Worksets grouped by scope id."""
1335
1333
1336
- def __init__ (self ):
1334
+ def __init__ (self ) -> None :
1337
1335
self ._workset_by_scope : OrderedDict [str , _ScopeWorkset ] = OrderedDict ()
1338
1336
1339
- def __repr__ (self ):
1337
+ def __repr__ (self ) -> str :
1340
1338
return (
1341
1339
f"<{ self .__class__ .__name__ } : "
1342
1340
f"num_worksets={ len (self ._workset_by_scope )} >"
0 commit comments