55from typing import TYPE_CHECKING , NamedTuple
66
77if TYPE_CHECKING :
8- from typing import Dict , List , Tuple
9-
108 from _pytest import nodes
119
1210
1311class TestGroup (NamedTuple ):
14- selected : "List [nodes.Item]"
15- deselected : "List [nodes.Item]"
12+ selected : "list [nodes.Item]"
13+ deselected : "list [nodes.Item]"
1614 duration : float
1715
1816
@@ -21,8 +19,8 @@ class AlgorithmBase(ABC):
2119
2220 @abstractmethod
2321 def __call__ (
24- self , splits : int , items : "List [nodes.Item]" , durations : "Dict [str, float]"
25- ) -> "List [TestGroup]" :
22+ self , splits : int , items : "list [nodes.Item]" , durations : "dict [str, float]"
23+ ) -> "list [TestGroup]" :
2624 pass
2725
2826 def __hash__ (self ) -> int :
@@ -52,8 +50,8 @@ class LeastDurationAlgorithm(AlgorithmBase):
5250 """
5351
5452 def __call__ (
55- self , splits : int , items : "List [nodes.Item]" , durations : "Dict [str, float]"
56- ) -> "List [TestGroup]" :
53+ self , splits : int , items : "list [nodes.Item]" , durations : "dict [str, float]"
54+ ) -> "list [TestGroup]" :
5755 items_with_durations = _get_items_with_durations (items , durations )
5856
5957 # add index of item in list
@@ -71,12 +69,12 @@ def __call__(
7169 items_with_durations_indexed , key = lambda tup : tup [1 ], reverse = True
7270 )
7371
74- selected : List [ List [ Tuple [nodes .Item , int ]]] = [[] for _ in range (splits )]
75- deselected : List [ List [nodes .Item ]] = [[] for _ in range (splits )]
76- duration : List [float ] = [0 for _ in range (splits )]
72+ selected : list [ list [ tuple [nodes .Item , int ]]] = [[] for _ in range (splits )]
73+ deselected : list [ list [nodes .Item ]] = [[] for _ in range (splits )]
74+ duration : list [float ] = [0 for _ in range (splits )]
7775
7876 # create a heap of the form (summed_durations, group_index)
79- heap : List [ Tuple [float , int ]] = [(0 , i ) for i in range (splits )]
77+ heap : list [ tuple [float , int ]] = [(0 , i ) for i in range (splits )]
8078 heapq .heapify (heap )
8179 for item , item_duration , original_index in sorted_items_with_durations :
8280 # get group with smallest sum
@@ -122,14 +120,14 @@ class DurationBasedChunksAlgorithm(AlgorithmBase):
122120 """
123121
124122 def __call__ (
125- self , splits : int , items : "List [nodes.Item]" , durations : "Dict [str, float]"
126- ) -> "List [TestGroup]" :
123+ self , splits : int , items : "list [nodes.Item]" , durations : "dict [str, float]"
124+ ) -> "list [TestGroup]" :
127125 items_with_durations = _get_items_with_durations (items , durations )
128126 time_per_group = sum (map (itemgetter (1 ), items_with_durations )) / splits
129127
130- selected : List [ List [nodes .Item ]] = [[] for i in range (splits )]
131- deselected : List [ List [nodes .Item ]] = [[] for i in range (splits )]
132- duration : List [float ] = [0 for i in range (splits )]
128+ selected : list [ list [nodes .Item ]] = [[] for i in range (splits )]
129+ deselected : list [ list [nodes .Item ]] = [[] for i in range (splits )]
130+ duration : list [float ] = [0 for i in range (splits )]
133131
134132 group_idx = 0
135133 for item , item_duration in items_with_durations :
@@ -151,8 +149,8 @@ def __call__(
151149
152150
153151def _get_items_with_durations (
154- items : "List [nodes.Item]" , durations : "Dict [str, float]"
155- ) -> "List[Tuple [nodes.Item, float]]" :
152+ items : "list [nodes.Item]" , durations : "dict [str, float]"
153+ ) -> "list[tuple [nodes.Item, float]]" :
156154 durations = _remove_irrelevant_durations (items , durations )
157155 avg_duration_per_test = _get_avg_duration_per_test (durations )
158156 items_with_durations = [
@@ -161,7 +159,7 @@ def _get_items_with_durations(
161159 return items_with_durations
162160
163161
164- def _get_avg_duration_per_test (durations : "Dict [str, float]" ) -> float :
162+ def _get_avg_duration_per_test (durations : "dict [str, float]" ) -> float :
165163 if durations :
166164 avg_duration_per_test = sum (durations .values ()) / len (durations )
167165 else :
@@ -171,8 +169,8 @@ def _get_avg_duration_per_test(durations: "Dict[str, float]") -> float:
171169
172170
173171def _remove_irrelevant_durations (
174- items : "List [nodes.Item]" , durations : "Dict [str, float]"
175- ) -> "Dict [str, float]" :
172+ items : "list [nodes.Item]" , durations : "dict [str, float]"
173+ ) -> "dict [str, float]" :
176174 # Filtering down durations to relevant ones ensures the avg isn't skewed by irrelevant data
177175 test_ids = [item .nodeid for item in items ]
178176 durations = {name : durations [name ] for name in test_ids if name in durations }
@@ -184,5 +182,5 @@ class Algorithms(enum.Enum):
184182 least_duration = LeastDurationAlgorithm ()
185183
186184 @staticmethod
187- def names () -> "List [str]" :
185+ def names () -> "list [str]" :
188186 return [x .name for x in Algorithms ]
0 commit comments