Skip to content

Commit f7fa9ae

Browse files
author
Tobias Deiminger
committed
Let reorder_items use our new parameter key
Fixes test reordering for indirect parameterization (see #8913). Prior to this commit, reorder_items considered the parameter index to tell if a parameter is "the same" and therefore can be shared. Looking at the index causes trouble if there are multiple parametrizations for the same fixture, basically because one index means different things in different parameter lists. This is fixed here by using the recently introduced parameter key as grouping criterion. Caution: The parameter key ends up inside the key of another dict, and therefore must be hashable. CallSpec2.param_keys is crafted sufficiently, it guarantees to contain comparable and hashable values.
1 parent 1a40eb1 commit f7fa9ae

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/_pytest/fixtures.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,21 +249,21 @@ def get_parametrized_fixture_keys(item: nodes.Item, scope: Scope) -> Iterator[_K
249249
pass
250250
else:
251251
cs: CallSpec2 = callspec
252-
# cs.indices.items() is random order of argnames. Need to
252+
# cs.param_keys.items() is random order of argnames. Need to
253253
# sort this so that different calls to
254254
# get_parametrized_fixture_keys will be deterministic.
255-
for argname, param_index in sorted(cs.indices.items()):
255+
for argname, param_key in sorted(cs.param_keys.items()):
256256
if cs._arg2scope[argname] != scope:
257257
continue
258258
if scope is Scope.Session:
259-
key: _Key = (argname, param_index)
259+
key: _Key = (argname, param_key)
260260
elif scope is Scope.Package:
261-
key = (argname, param_index, item.path.parent)
261+
key = (argname, param_key, item.path.parent)
262262
elif scope is Scope.Module:
263-
key = (argname, param_index, item.path)
263+
key = (argname, param_key, item.path)
264264
elif scope is Scope.Class:
265265
item_cls = item.cls # type: ignore[attr-defined]
266-
key = (argname, param_index, item.path, item_cls)
266+
key = (argname, param_key, item.path, item_cls)
267267
else:
268268
assert_never(scope)
269269
yield key

0 commit comments

Comments
 (0)