Objects passed to the :hook:`pytest_generate_tests` hook. They help to inspect a test function and to generate tests according to test configuration or values specified in the class or module where a test function is defined.
| 1184 | |
| 1185 | @final |
| 1186 | class Metafunc: |
| 1187 | """Objects passed to the :hook:`pytest_generate_tests` hook. |
| 1188 | |
| 1189 | They help to inspect a test function and to generate tests according to |
| 1190 | test configuration or values specified in the class or module where a |
| 1191 | test function is defined. |
| 1192 | """ |
| 1193 | |
| 1194 | def __init__( |
| 1195 | self, |
| 1196 | definition: FunctionDefinition, |
| 1197 | fixtureinfo: fixtures.FuncFixtureInfo, |
| 1198 | config: Config, |
| 1199 | cls=None, |
| 1200 | module=None, |
| 1201 | *, |
| 1202 | _ispytest: bool = False, |
| 1203 | ) -> None: |
| 1204 | check_ispytest(_ispytest) |
| 1205 | |
| 1206 | #: Access to the underlying :class:`_pytest.python.FunctionDefinition`. |
| 1207 | self.definition = definition |
| 1208 | |
| 1209 | #: Access to the :class:`pytest.Config` object for the test session. |
| 1210 | self.config = config |
| 1211 | |
| 1212 | #: The module object where the test function is defined in. |
| 1213 | self.module = module |
| 1214 | |
| 1215 | #: Underlying Python test function. |
| 1216 | self.function = definition.obj |
| 1217 | |
| 1218 | #: Set of fixture names required by the test function. |
| 1219 | self.fixturenames = fixtureinfo.names_closure |
| 1220 | |
| 1221 | #: Class object where the test function is defined in or ``None``. |
| 1222 | self.cls = cls |
| 1223 | |
| 1224 | self._arg2fixturedefs = fixtureinfo.name2fixturedefs |
| 1225 | |
| 1226 | # Result of parametrize(). |
| 1227 | self._calls: list[CallSpec2] = [] |
| 1228 | |
| 1229 | self._params_directness: dict[str, Literal["indirect", "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 | """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 |