Skip to content

Commit 9bea1be

Browse files
committed
fixtures: remove a no longer needed sort
Dicts these days preserve order, so the sort is no longer needed to achieve determinism. As shown by the `test_dynamic_parametrized_ordering` test, this can change the ordering of items, but only in equivalent ways (same number of setups/teardowns per scope), it will just respect the user's given ordering better (hence `vxlan` items now ordered before `vlan` items compared to the previous ordering).
1 parent 2007cf6 commit 9bea1be

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/_pytest/fixtures.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,7 @@ def get_parametrized_fixture_keys(
172172
callspec: CallSpec2 = item.callspec # type: ignore[attr-defined]
173173
except AttributeError:
174174
return
175-
# cs.indices is random order of argnames. Need to
176-
# sort this so that different calls to
177-
# get_parametrized_fixture_keys will be deterministic.
178-
for argname in sorted(callspec.indices):
175+
for argname in callspec.indices:
179176
if callspec._arg2scope[argname] != scope:
180177
continue
181178

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)