MCPcopy
hub / github.com/pytest-dev/pytest / _find_parametrized_scope

Function _find_parametrized_scope

src/_pytest/python.py:1529–1558  ·  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: bool | Sequence[str],
)

Source from the content-addressed store, hash-verified

1527
1528
1529def _find_parametrized_scope(
1530 argnames: Sequence[str],
1531 arg2fixturedefs: Mapping[str, Sequence[fixtures.FixtureDef[object]]],
1532 indirect: bool | Sequence[str],
1533) -> Scope:
1534 """Find the most appropriate scope for a parametrized call based on its arguments.
1535
1536 When there's at least one direct argument, always use "function" scope.
1537
1538 When a test function is parametrized and all its arguments are indirect
1539 (e.g. fixtures), return the most narrow scope based on the fixtures used.
1540
1541 Related to issue #1832, based on code posted by @Kingdread.
1542 """
1543 if isinstance(indirect, Sequence):
1544 all_arguments_are_fixtures = len(indirect) == len(argnames)
1545 else:
1546 all_arguments_are_fixtures = bool(indirect)
1547
1548 if all_arguments_are_fixtures:
1549 fixturedefs = arg2fixturedefs or {}
1550 used_scopes = [
1551 fixturedef[-1]._scope
1552 for name, fixturedef in fixturedefs.items()
1553 if name in argnames
1554 ]
1555 # Takes the most narrow scope from used fixtures.
1556 return min(used_scopes, default=Scope.Function)
1557
1558 return Scope.Function
1559
1560
1561def _ascii_escaped_by_config(val: str | bytes, config: Config | None) -> str:

Callers 2

find_scopeMethod · 0.90
parametrizeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected