Register a fixture imperatively. This is an advanced function intended for use by plugins. Normally, fixtures should be registered declaratively using the :func:`@pytest.fixture <pytest.fixture>` decorator. Pytest looks for these fixture definitions during the collection phase and
(
*,
name: str,
func: _FixtureFunc[object],
node: nodes.Node,
scope: ScopeName | Callable[[str, Config], ScopeName] = "function",
params: Sequence[object] | None = None,
ids: tuple[object | None, ...] | Callable[[Any], object | None] | None = None,
autouse: bool = False,
)
| 2335 | |
| 2336 | |
| 2337 | def register_fixture( |
| 2338 | *, |
| 2339 | name: str, |
| 2340 | func: _FixtureFunc[object], |
| 2341 | node: nodes.Node, |
| 2342 | scope: ScopeName | Callable[[str, Config], ScopeName] = "function", |
| 2343 | params: Sequence[object] | None = None, |
| 2344 | ids: tuple[object | None, ...] | Callable[[Any], object | None] | None = None, |
| 2345 | autouse: bool = False, |
| 2346 | ) -> None: |
| 2347 | """Register a fixture imperatively. |
| 2348 | |
| 2349 | This is an advanced function intended for use by plugins. |
| 2350 | |
| 2351 | Normally, fixtures should be registered declaratively using the |
| 2352 | :func:`@pytest.fixture <pytest.fixture>` decorator. Pytest looks for these |
| 2353 | fixture definitions during the collection phase and registers them |
| 2354 | automatically. For some plugin usecases the declarative interface can be |
| 2355 | cumbersome or nonviable, in which case the imperative interface can be used. |
| 2356 | |
| 2357 | Fixture registration is expected to happen during the collection phase, and |
| 2358 | this is the only sanctioned use. However, to allow for more creative uses, |
| 2359 | this is not enforced. But do so at your own risk! |
| 2360 | |
| 2361 | .. versionadded: 9.1 |
| 2362 | |
| 2363 | :param name: |
| 2364 | The fixture's name. |
| 2365 | :param func: |
| 2366 | The fixture's implementation function. |
| 2367 | :param node: |
| 2368 | The visibility of the fixture. |
| 2369 | |
| 2370 | Only items that are descendents of this node in the collection tree will |
| 2371 | be able to request this fixture. You can think of this as the place |
| 2372 | where you would put the `@pytest.fixture`. |
| 2373 | |
| 2374 | For global visibility, pass the :class:`session <pytest.Session>` node, |
| 2375 | which is the root of the collection tree. |
| 2376 | :param scope: |
| 2377 | The fixture's scope. |
| 2378 | :param params: |
| 2379 | The fixture's parametrization params. |
| 2380 | :param ids: |
| 2381 | The fixture's IDs. |
| 2382 | :param autouse: |
| 2383 | Whether this is an autouse fixture. |
| 2384 | """ |
| 2385 | node.session._fixturemanager._register_fixture( |
| 2386 | name=name, |
| 2387 | func=func, |
| 2388 | node=node, |
| 2389 | scope=scope, |
| 2390 | params=params, |
| 2391 | ids=ids, |
| 2392 | autouse=autouse, |
| 2393 | ) |
nothing calls this directly
no test coverage detected