From 9bea1be2157e8467712aa1de46312ed0827741d8 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Wed, 21 Feb 2024 10:00:16 +0200 Subject: [PATCH] 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). --- src/_pytest/fixtures.py | 5 +---- testing/python/fixtures.py | 8 ++++---- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index b13d9e703..935d2b9a0 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -172,10 +172,7 @@ def get_parametrized_fixture_keys( callspec: CallSpec2 = item.callspec # type: ignore[attr-defined] except AttributeError: return - # cs.indices is random order of argnames. Need to - # sort this so that different calls to - # get_parametrized_fixture_keys will be deterministic. - for argname in sorted(callspec.indices): + for argname in callspec.indices: if callspec._arg2scope[argname] != scope: continue diff --git a/testing/python/fixtures.py b/testing/python/fixtures.py index 0fb5aa450..299e411a6 100644 --- a/testing/python/fixtures.py +++ b/testing/python/fixtures.py @@ -2730,12 +2730,12 @@ class TestFixtureMarker: """ test_dynamic_parametrized_ordering.py::test[flavor1-vxlan] PASSED test_dynamic_parametrized_ordering.py::test2[flavor1-vxlan] PASSED - test_dynamic_parametrized_ordering.py::test[flavor2-vxlan] PASSED - test_dynamic_parametrized_ordering.py::test2[flavor2-vxlan] PASSED - test_dynamic_parametrized_ordering.py::test[flavor2-vlan] PASSED - test_dynamic_parametrized_ordering.py::test2[flavor2-vlan] PASSED test_dynamic_parametrized_ordering.py::test[flavor1-vlan] PASSED test_dynamic_parametrized_ordering.py::test2[flavor1-vlan] PASSED + test_dynamic_parametrized_ordering.py::test[flavor2-vlan] PASSED + test_dynamic_parametrized_ordering.py::test2[flavor2-vlan] PASSED + test_dynamic_parametrized_ordering.py::test[flavor2-vxlan] PASSED + test_dynamic_parametrized_ordering.py::test2[flavor2-vxlan] PASSED """ )