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

Method parametrize

src/_pytest/python.py:1041–1173  ·  view source on GitHub ↗

Add new invocations to the underlying test function using the list of argvalues for the given argnames. Parametrization is performed during the collection phase. If you need to setup expensive resources see about setting indirect to do it rather than at test setup time.

(
        self,
        argnames: Union[str, List[str], Tuple[str, ...]],
        argvalues: Iterable[Union[ParameterSet, Sequence[object], object]],
        indirect: Union[bool, Sequence[str]] = False,
        ids: Optional[
            Union[
                Iterable[Union[None, str, float, int, bool]],
                Callable[[Any], Optional[object]],
            ]
        ] = None,
        scope: "Optional[_ScopeName]" = None,
        *,
        _param_mark: Optional[Mark] = None,
    )

Source from the content-addressed store, hash-verified

1039 self._calls: List[CallSpec2] = []
1040
1041 def parametrize(
1042 self,
1043 argnames: Union[str, List[str], Tuple[str, ...]],
1044 argvalues: Iterable[Union[ParameterSet, Sequence[object], object]],
1045 indirect: Union[bool, Sequence[str]] = False,
1046 ids: Optional[
1047 Union[
1048 Iterable[Union[None, str, float, int, bool]],
1049 Callable[[Any], Optional[object]],
1050 ]
1051 ] = None,
1052 scope: "Optional[_ScopeName]" = None,
1053 *,
1054 _param_mark: Optional[Mark] = None,
1055 ) -> None:
1056 """Add new invocations to the underlying test function using the list
1057 of argvalues for the given argnames. Parametrization is performed
1058 during the collection phase. If you need to setup expensive resources
1059 see about setting indirect to do it rather than at test setup time.
1060
1061 Can be called multiple times, in which case each call parametrizes all
1062 previous parametrizations, e.g.
1063
1064 ::
1065
1066 unparametrized: t
1067 parametrize ["x", "y"]: t[x], t[y]
1068 parametrize [1, 2]: t[x-1], t[x-2], t[y-1], t[y-2]
1069
1070 :param argnames:
1071 A comma-separated string denoting one or more argument names, or
1072 a list/tuple of argument strings.
1073
1074 :param argvalues:
1075 The list of argvalues determines how often a test is invoked with
1076 different argument values.
1077
1078 If only one argname was specified argvalues is a list of values.
1079 If N argnames were specified, argvalues must be a list of
1080 N-tuples, where each tuple-element specifies a value for its
1081 respective argname.
1082
1083 :param indirect:
1084 A list of arguments' names (subset of argnames) or a boolean.
1085 If True the list contains all names from the argnames. Each
1086 argvalue corresponding to an argname in this list will
1087 be passed as request.param to its respective argname fixture
1088 function so that it can perform more expensive setups during the
1089 setup phase of a test rather than at collection time.
1090
1091 :param ids:
1092 Sequence of (or generator for) ids for ``argvalues``,
1093 or a callable to return part of the id for each argvalue.
1094
1095 With sequences (and generators like ``itertools.count()``) the
1096 returned ids should be of type ``string``, ``int``, ``float``,
1097 ``bool``, or ``None``.
1098 They are mapped to the corresponding index in ``argvalues``.

Calls 10

_resolve_arg_idsMethod · 0.95
failFunction · 0.90
_find_parametrized_scopeFunction · 0.85
CallSpec2Class · 0.85
_for_parametrizeMethod · 0.80
from_userMethod · 0.80
setmultiMethod · 0.80
appendMethod · 0.80