MCPcopy Create free account
hub / github.com/pytest-dev/pytest / _find_parametrized_scope

Function _find_parametrized_scope

src/_pytest/python.py:1318–1347  ·  view source on GitHub ↗

Find the most appropriate scope for a parametrized call based on its arguments. When there's at least one direct argument, always use "function" scope. When a test function is parametrized and all its arguments are indirect (e.g. fixtures), return the most narrow scope based on the fix

(
    argnames: Sequence[str],
    arg2fixturedefs: Mapping[str, Sequence[fixtures.FixtureDef[object]]],
    indirect: Union[bool, Sequence[str]],
)

Source from the content-addressed store, hash-verified

1316
1317
1318def _find_parametrized_scope(
1319 argnames: Sequence[str],
1320 arg2fixturedefs: Mapping[str, Sequence[fixtures.FixtureDef[object]]],
1321 indirect: Union[bool, Sequence[str]],
1322) -> Scope:
1323 """Find the most appropriate scope for a parametrized call based on its arguments.
1324
1325 When there's at least one direct argument, always use "function" scope.
1326
1327 When a test function is parametrized and all its arguments are indirect
1328 (e.g. fixtures), return the most narrow scope based on the fixtures used.
1329
1330 Related to issue #1832, based on code posted by @Kingdread.
1331 """
1332 if isinstance(indirect, Sequence):
1333 all_arguments_are_fixtures = len(indirect) == len(argnames)
1334 else:
1335 all_arguments_are_fixtures = bool(indirect)
1336
1337 if all_arguments_are_fixtures:
1338 fixturedefs = arg2fixturedefs or {}
1339 used_scopes = [
1340 fixturedef[0]._scope
1341 for name, fixturedef in fixturedefs.items()
1342 if name in argnames
1343 ]
1344 # Takes the most narrow scope from used fixtures.
1345 return min(used_scopes, default=Scope.Function)
1346
1347 return Scope.Function
1348
1349
1350def _ascii_escaped_by_config(val: Union[str, bytes], config: Optional[Config]) -> str:

Callers 2

find_scopeMethod · 0.90
parametrizeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected