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

Function _resolve_args_directness

src/_pytest/fixtures.py:1614–1650  ·  view source on GitHub ↗

Resolve if each parametrized argument must be considered an indirect parameter to a fixture of the same name, or a direct parameter to the parametrized function, based on the ``indirect`` parameter of the parametrize() call. :param argnames: List of argument names passed to

(
    argnames: Sequence[str],
    indirect: bool | Sequence[str],
    nodeid: str,
)

Source from the content-addressed store, hash-verified

1612
1613
1614def _resolve_args_directness(
1615 argnames: Sequence[str],
1616 indirect: bool | Sequence[str],
1617 nodeid: str,
1618) -> dict[str, Literal["indirect", "direct"]]:
1619 """Resolve if each parametrized argument must be considered an indirect
1620 parameter to a fixture of the same name, or a direct parameter to the
1621 parametrized function, based on the ``indirect`` parameter of the
1622 parametrize() call.
1623
1624 :param argnames:
1625 List of argument names passed to ``parametrize()``.
1626 :param indirect:
1627 Same as the ``indirect`` parameter of ``parametrize()``.
1628 :param nodeid:
1629 Node ID to which the parametrization is applied.
1630 :returns:
1631 A dict mapping each arg name to either "indirect" or "direct".
1632 """
1633 arg_directness: dict[str, Literal["indirect", "direct"]]
1634 if isinstance(indirect, bool):
1635 arg_directness = dict.fromkeys(argnames, "indirect" if indirect else "direct")
1636 elif isinstance(indirect, Sequence):
1637 arg_directness = dict.fromkeys(argnames, "direct")
1638 for arg in indirect:
1639 if arg not in argnames:
1640 fail(
1641 f"In {nodeid}: indirect fixture '{arg}' doesn't exist",
1642 pytrace=False,
1643 )
1644 arg_directness[arg] = "indirect"
1645 else:
1646 fail(
1647 f"In {nodeid}: expected Sequence or boolean for indirect, got {type(indirect).__name__}",
1648 pytrace=False,
1649 )
1650 return arg_directness
1651
1652
1653def _get_direct_parametrize_args(node: nodes.Node) -> set[str]:

Callers 2

parametrizeMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected