Merge pull request #12019 from bluetech/fixtures-simplify

fixtures: remove a no longer needed sort
This commit is contained in:
Ran Benita 2024-02-22 21:52:56 +02:00 committed by GitHub
commit 691d8fcafb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 31 deletions

View File

@ -169,16 +169,11 @@ def get_parametrized_fixture_keys(
the specified scope.""" the specified scope."""
assert scope is not Scope.Function assert scope is not Scope.Function
try: try:
callspec = item.callspec # type: ignore[attr-defined] callspec: CallSpec2 = item.callspec # type: ignore[attr-defined]
except AttributeError: except AttributeError:
pass return
else: for argname in callspec.indices:
cs: CallSpec2 = callspec if callspec._arg2scope[argname] != scope:
# 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(cs.indices):
if cs._arg2scope[argname] != scope:
continue continue
item_cls = None item_cls = None
@ -194,7 +189,7 @@ def get_parametrized_fixture_keys(
else: else:
assert_never(scope) assert_never(scope)
param_index = cs.indices[argname] param_index = callspec.indices[argname]
yield FixtureArgKey(argname, param_index, scoped_item_path, item_cls) yield FixtureArgKey(argname, param_index, scoped_item_path, item_cls)

View File

@ -1267,7 +1267,6 @@ class Metafunc:
# Add funcargs as fixturedefs to fixtureinfo.arg2fixturedefs by registering # Add funcargs as fixturedefs to fixtureinfo.arg2fixturedefs by registering
# artificial "pseudo" FixtureDef's so that later at test execution time we can # artificial "pseudo" FixtureDef's so that later at test execution time we can
# rely on a proper FixtureDef to exist for fixture setup. # rely on a proper FixtureDef to exist for fixture setup.
arg2fixturedefs = self._arg2fixturedefs
node = None node = None
# If we have a scope that is higher than function, we need # If we have a scope that is higher than function, we need
# to make sure we only ever create an according fixturedef on # to make sure we only ever create an according fixturedef on
@ -1281,7 +1280,7 @@ class Metafunc:
# If used class scope and there is no class, use module-level # If used class scope and there is no class, use module-level
# collector (for now). # collector (for now).
if scope_ is Scope.Class: if scope_ is Scope.Class:
assert isinstance(collector, _pytest.python.Module) assert isinstance(collector, Module)
node = collector node = collector
# If used package scope and there is no package, use session # If used package scope and there is no package, use session
# (for now). # (for now).
@ -1316,7 +1315,7 @@ class Metafunc:
) )
if name2pseudofixturedef is not None: if name2pseudofixturedef is not None:
name2pseudofixturedef[argname] = fixturedef name2pseudofixturedef[argname] = fixturedef
arg2fixturedefs[argname] = [fixturedef] self._arg2fixturedefs[argname] = [fixturedef]
# Create the new calls: if we are parametrize() multiple times (by applying the decorator # Create the new calls: if we are parametrize() multiple times (by applying the decorator
# more than once) then we accumulate those calls generating the cartesian product # more than once) then we accumulate those calls generating the cartesian product

View File

@ -2730,12 +2730,12 @@ class TestFixtureMarker:
""" """
test_dynamic_parametrized_ordering.py::test[flavor1-vxlan] PASSED test_dynamic_parametrized_ordering.py::test[flavor1-vxlan] PASSED
test_dynamic_parametrized_ordering.py::test2[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::test[flavor1-vlan] PASSED
test_dynamic_parametrized_ordering.py::test2[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
""" """
) )