@@ -171,22 +171,30 @@ def getfixturemarker(obj: object) -> FixtureFunctionMarker | None:
171
171
172
172
173
173
@dataclasses .dataclass (frozen = True )
174
- class FixtureArgKey :
174
+ class ParamArgKey :
175
+ """A key for a high-scoped parameter used by an item.
176
+
177
+ For use as a hashable key in `reorder_items`. The combination of fields
178
+ is meant to uniquely identify a particular "instance" of a param,
179
+ potentially shared by multiple items in a scope.
180
+ """
181
+
182
+ #: The param name.
175
183
argname : str
176
184
param_index : int
185
+ #: For scopes Package, Module, Class, the path to the file (directory in
186
+ #: Package's case) of the package/module/class where the item is defined.
177
187
scoped_item_path : Path | None
188
+ #: For Class scope, the class where the item is defined.
178
189
item_cls : type | None
179
190
180
191
181
192
_V = TypeVar ("_V" )
182
193
OrderedSet = dict [_V , None ]
183
194
184
195
185
- def get_parametrized_fixture_argkeys (
186
- item : nodes .Item , scope : Scope
187
- ) -> Iterator [FixtureArgKey ]:
188
- """Return list of keys for all parametrized arguments which match
189
- the specified scope."""
196
+ def get_param_argkeys (item : nodes .Item , scope : Scope ) -> Iterator [ParamArgKey ]:
197
+ """Return all ParamArgKeys for item matching the specified high scope."""
190
198
assert scope is not Scope .Function
191
199
192
200
try :
@@ -212,19 +220,17 @@ def get_parametrized_fixture_argkeys(
212
220
if callspec ._arg2scope [argname ] != scope :
213
221
continue
214
222
param_index = callspec .indices [argname ]
215
- yield FixtureArgKey (argname , param_index , scoped_item_path , item_cls )
223
+ yield ParamArgKey (argname , param_index , scoped_item_path , item_cls )
216
224
217
225
218
226
def reorder_items (items : Sequence [nodes .Item ]) -> list [nodes .Item ]:
219
- argkeys_by_item : dict [Scope , dict [nodes .Item , OrderedSet [FixtureArgKey ]]] = {}
220
- items_by_argkey : dict [
221
- Scope , dict [FixtureArgKey , OrderedDict [nodes .Item , None ]]
222
- ] = {}
227
+ argkeys_by_item : dict [Scope , dict [nodes .Item , OrderedSet [ParamArgKey ]]] = {}
228
+ items_by_argkey : dict [Scope , dict [ParamArgKey , OrderedDict [nodes .Item , None ]]] = {}
223
229
for scope in HIGH_SCOPES :
224
230
scoped_argkeys_by_item = argkeys_by_item [scope ] = {}
225
231
scoped_items_by_argkey = items_by_argkey [scope ] = defaultdict (OrderedDict )
226
232
for item in items :
227
- argkeys = dict .fromkeys (get_parametrized_fixture_argkeys (item , scope ))
233
+ argkeys = dict .fromkeys (get_param_argkeys (item , scope ))
228
234
if argkeys :
229
235
scoped_argkeys_by_item [item ] = argkeys
230
236
for argkey in argkeys :
@@ -240,9 +246,9 @@ def reorder_items(items: Sequence[nodes.Item]) -> list[nodes.Item]:
240
246
241
247
def reorder_items_atscope (
242
248
items : OrderedSet [nodes .Item ],
243
- argkeys_by_item : Mapping [Scope , Mapping [nodes .Item , OrderedSet [FixtureArgKey ]]],
249
+ argkeys_by_item : Mapping [Scope , Mapping [nodes .Item , OrderedSet [ParamArgKey ]]],
244
250
items_by_argkey : Mapping [
245
- Scope , Mapping [FixtureArgKey , OrderedDict [nodes .Item , None ]]
251
+ Scope , Mapping [ParamArgKey , OrderedDict [nodes .Item , None ]]
246
252
],
247
253
scope : Scope ,
248
254
) -> OrderedSet [nodes .Item ]:
@@ -252,7 +258,7 @@ def reorder_items_atscope(
252
258
scoped_items_by_argkey = items_by_argkey [scope ]
253
259
scoped_argkeys_by_item = argkeys_by_item [scope ]
254
260
255
- ignore : set [FixtureArgKey ] = set ()
261
+ ignore : set [ParamArgKey ] = set ()
256
262
items_deque = deque (items )
257
263
items_done : OrderedSet [nodes .Item ] = {}
258
264
while items_deque :
0 commit comments