Skip to content

Commit 2007cf6

Browse files
committed
fixtures: remove a level of indentation
A bit easier to follow.
1 parent 79def57 commit 2007cf6

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

src/_pytest/fixtures.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -169,33 +169,31 @@ 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+
# 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):
179+
if callspec._arg2scope[argname] != scope:
180+
continue
181+
182+
item_cls = None
183+
if scope is Scope.Session:
184+
scoped_item_path = None
185+
elif scope is Scope.Package:
186+
scoped_item_path = item.path
187+
elif scope is Scope.Module:
188+
scoped_item_path = item.path
189+
elif scope is Scope.Class:
190+
scoped_item_path = item.path
191+
item_cls = item.cls # type: ignore[attr-defined]
192+
else:
193+
assert_never(scope)
196194

197-
param_index = cs.indices[argname]
198-
yield FixtureArgKey(argname, param_index, scoped_item_path, item_cls)
195+
param_index = callspec.indices[argname]
196+
yield FixtureArgKey(argname, param_index, scoped_item_path, item_cls)
199197

200198

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

0 commit comments

Comments
 (0)