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 at test setup time instead.
(
self,
argnames: str | Sequence[str],
argvalues: Iterable[ParameterSet | Sequence[object] | object],
indirect: bool | Sequence[str] = False,
ids: Iterable[object | None] | Callable[[Any], object | None] | None = None,
scope: ScopeName | None = None,
*,
_param_mark: Mark | None = None,
)
| 1229 | self._params_directness: dict[str, Literal[class="st">"indirect", class="st">"direct"]] = {} |
| 1230 | |
| 1231 | def parametrize( |
| 1232 | self, |
| 1233 | argnames: str | Sequence[str], |
| 1234 | argvalues: Iterable[ParameterSet | Sequence[object] | object], |
| 1235 | indirect: bool | Sequence[str] = False, |
| 1236 | ids: Iterable[object | None] | Callable[[Any], object | None] | None = None, |
| 1237 | scope: ScopeName | None = None, |
| 1238 | *, |
| 1239 | _param_mark: Mark | None = None, |
| 1240 | ) -> None: |
| 1241 | class="st">"""Add new invocations to the underlying test function using the list |
| 1242 | of argvalues for the given argnames. Parametrization is performed |
| 1243 | during the collection phase. If you need to setup expensive resources |
| 1244 | see about setting ``indirect`` to do it at test setup time instead. |
| 1245 | |
| 1246 | Can be called multiple times per test function (but only on different |
| 1247 | argument names), in which case each call parametrizes all previous |
| 1248 | parametrizations, e.g. |
| 1249 | |
| 1250 | :: |
| 1251 | |
| 1252 | unparametrized: t |
| 1253 | parametrize [class="st">"x", class="st">"y"]: t[x], t[y] |
| 1254 | parametrize [1, 2]: t[x-1], t[x-2], t[y-1], t[y-2] |
| 1255 | |
| 1256 | :param argnames: |
| 1257 | A comma-separated string denoting one or more argument names, or |
| 1258 | a list/tuple of argument strings. |
| 1259 | |
| 1260 | :param argvalues: |
| 1261 | The list of argvalues determines how often a test is invoked with |
| 1262 | different argument values. |
| 1263 | |
| 1264 | If only one argname was specified argvalues is a list of values. |
| 1265 | If N argnames were specified, argvalues must be a list of |
| 1266 | N-tuples, where each tuple-element specifies a value for its |
| 1267 | respective argname. |
| 1268 | |
| 1269 | .. versionchanged:: 9.1 |
| 1270 | |
| 1271 | Passing a non-:class:`~collections.abc.Collection` iterable |
| 1272 | (such as a generator or iterator) is deprecated. See |
| 1273 | :ref:`parametrize-iterators` for details. |
| 1274 | |
| 1275 | :param indirect: |
| 1276 | A list of arguments&class="cm">#x27; names (subset of argnames) or a boolean. |
| 1277 | If True the list contains all names from the argnames. Each |
| 1278 | argvalue corresponding to an argname in this list will |
| 1279 | be passed as request.param to its respective argname fixture |
| 1280 | function so that it can perform more expensive setups during the |
| 1281 | setup phase of a test rather than at collection time. |
| 1282 | |
| 1283 | :param ids: |
| 1284 | Sequence of (or generator for) ids for ``argvalues``, |
| 1285 | or a callable to return part of the id for each argvalue. |
| 1286 | |
| 1287 | With sequences (and generators like ``itertools.count()``) the |
| 1288 | returned ids should be of type ``string``, ``int``, ``float``, |