Skip to content

Commit 691d8fc

Browse files
authored
Merge pull request #12019 from bluetech/fixtures-simplify
fixtures: remove a no longer needed sort
2 parents c5c729e + 9bea1be commit 691d8fc

File tree

3 files changed

+26
-32
lines changed

3 files changed

+26
-32
lines changed

src/_pytest/fixtures.py

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -169,33 +169,28 @@ def get_parametrized_fixture_keys(
169169
the specified scope."""
170170
assert scope is not Scope.Function
171171
try:
172-
callspec = item.callspec # type: ignore[attr-defined]
172+
callspec: CallSpec2 = item.callspec # type: ignore[attr-defined]
173173
except AttributeError:
174-
pass
175-
else:
176-
cs: CallSpec2 = callspec
177-
# cs.indices is random order of argnames. Need to
178-
# sort this so that different calls to
179-
# get_parametrized_fixture_keys will be deterministic.
180-
for argname in sorted(cs.indices):
181-
if cs._arg2scope[argname] != scope:
182-
continue
183-
184-
item_cls = None
185-
if scope is Scope.Session:
186-
scoped_item_path = None
187-
elif scope is Scope.Package:
188-
scoped_item_path = item.path
189-
elif scope is Scope.Module:
190-
scoped_item_path = item.path
191-
elif scope is Scope.Class:
192-
scoped_item_path = item.path
193-
item_cls = item.cls # type: ignore[attr-defined]
194-
else:
195-
assert_never(scope)
174+
return
175+
for argname in callspec.indices:
176+
if callspec._arg2scope[argname] != scope:
177+
continue
178+
179+
item_cls = None
180+
if scope is Scope.Session:
181+
scoped_item_path = None
182+
elif scope is Scope.Package:
183+
scoped_item_path = item.path
184+
elif scope is Scope.Module:
185+
scoped_item_path = item.path
186+
elif scope is Scope.Class:
187+
scoped_item_path = item.path
188+
item_cls = item.cls # type: ignore[attr-defined]
189+
else:
190+
assert_never(scope)
196191

197-
param_index = cs.indices[argname]
198-
yield FixtureArgKey(argname, param_index, scoped_item_path, item_cls)
192+
param_index = callspec.indices[argname]
193+
yield FixtureArgKey(argname, param_index, scoped_item_path, item_cls)
199194

200195

201196
# Algorithm for sorting on a per-parametrized resource setup basis.

src/_pytest/python.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,6 @@ def parametrize(
12671267
# Add funcargs as fixturedefs to fixtureinfo.arg2fixturedefs by registering
12681268
# artificial "pseudo" FixtureDef's so that later at test execution time we can
12691269
# rely on a proper FixtureDef to exist for fixture setup.
1270-
arg2fixturedefs = self._arg2fixturedefs
12711270
node = None
12721271
# If we have a scope that is higher than function, we need
12731272
# to make sure we only ever create an according fixturedef on
@@ -1281,7 +1280,7 @@ def parametrize(
12811280
# If used class scope and there is no class, use module-level
12821281
# collector (for now).
12831282
if scope_ is Scope.Class:
1284-
assert isinstance(collector, _pytest.python.Module)
1283+
assert isinstance(collector, Module)
12851284
node = collector
12861285
# If used package scope and there is no package, use session
12871286
# (for now).
@@ -1316,7 +1315,7 @@ def parametrize(
13161315
)
13171316
if name2pseudofixturedef is not None:
13181317
name2pseudofixturedef[argname] = fixturedef
1319-
arg2fixturedefs[argname] = [fixturedef]
1318+
self._arg2fixturedefs[argname] = [fixturedef]
13201319

13211320
# Create the new calls: if we are parametrize() multiple times (by applying the decorator
13221321
# more than once) then we accumulate those calls generating the cartesian product

testing/python/fixtures.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,12 +2730,12 @@ def test2(reprovision):
27302730
"""
27312731
test_dynamic_parametrized_ordering.py::test[flavor1-vxlan] PASSED
27322732
test_dynamic_parametrized_ordering.py::test2[flavor1-vxlan] PASSED
2733-
test_dynamic_parametrized_ordering.py::test[flavor2-vxlan] PASSED
2734-
test_dynamic_parametrized_ordering.py::test2[flavor2-vxlan] PASSED
2735-
test_dynamic_parametrized_ordering.py::test[flavor2-vlan] PASSED
2736-
test_dynamic_parametrized_ordering.py::test2[flavor2-vlan] PASSED
27372733
test_dynamic_parametrized_ordering.py::test[flavor1-vlan] PASSED
27382734
test_dynamic_parametrized_ordering.py::test2[flavor1-vlan] PASSED
2735+
test_dynamic_parametrized_ordering.py::test[flavor2-vlan] PASSED
2736+
test_dynamic_parametrized_ordering.py::test2[flavor2-vlan] PASSED
2737+
test_dynamic_parametrized_ordering.py::test[flavor2-vxlan] PASSED
2738+
test_dynamic_parametrized_ordering.py::test2[flavor2-vxlan] PASSED
27392739
"""
27402740
)
27412741

0 commit comments

Comments
 (0)