Utilities for attaching typed marks to pytest fixture functions and querying those marks during a test session.
Use pytest_userver.fixture_markers.mark to store an info object on the original function. Use pytest_userver.fixture_markers.get_infos to retrieve fixtures tagged with a particular info type among those visible to a request.
Marks are independent of @pytest.fixture: apply the mark to the original function, then wrap with @pytest.fixture.
Classes | |
| class | _MarkedFixture |
Functions | |
| Callable[..., object] | mark (Callable[..., object] func, object info) |
| Attach info to the original function func. | |
| dict[str, I] | get_infos (pytest.FixtureRequest request, type[I] info_type) |
| Return marked fixtures of info_type that are visible to a request. | |
| bool | _is_pytest_fixture_wrapper (object func) |
| Sequence[pytest.FixtureDef[object]]|None | _get_fixturedefs (Any fixture_manager, str name, Any key) |
| Iterator[pytest.FixtureDef[object]] | _iter_visible_fixtures (pytest.FixtureRequest request, Any key) |
| _MarkedFixture[I]|None | _marked_fixture_for_name (pytest.FixtureRequest request, str name, type[I] info_type, Any key) |
| I|None | _inherited_info (Sequence[pytest.FixtureDef[object]] matched, type[I] info_type) |
| int | _cmp_from_lt (Any a, Any b) |
| int | _cmp_marked_fixtures (_MarkedFixture[Any] left, _MarkedFixture[Any] right, dict[str, int] plugin_key_order) |
| str | _plugin_key (Any func) |
| int | _cmp_sites (pytest.FixtureDef[object] left, pytest.FixtureDef[object] right) |
| bool | _legacy_more_specific (pytest.FixtureDef[object] candidate, pytest.FixtureDef[object] other) |
| bool | _has_location (pytest.FixtureDef[object] fixturedef) |
| bool | _is_nested_baseid (str prefix, str full) |
| I|None | _mark_info (pytest.FixtureDef[object] fixturedef, type[I] info_type) |
Variables | |
| is_visibility_more_specific = None | |
| I = TypeVar('I') | |
| str | _MARKS_ATTR = '_testsuite_fixture_marks' |
| str | _MARKS_ORDER_ATTR = '_testsuite_fixture_marks_order' |
| _mark_order_counter = itertools.count() | |
| dict | _SCOPE_RANK |
|
protected |
Definition at line 241 of file fixture_markers.py.
|
protected |
Definition at line 245 of file fixture_markers.py.
|
protected |
Definition at line 269 of file fixture_markers.py.
|
protected |
Definition at line 175 of file fixture_markers.py.
|
protected |
Definition at line 298 of file fixture_markers.py.
|
protected |
Definition at line 229 of file fixture_markers.py.
|
protected |
Definition at line 302 of file fixture_markers.py.
|
protected |
Definition at line 169 of file fixture_markers.py.
|
protected |
Definition at line 183 of file fixture_markers.py.
|
protected |
Definition at line 281 of file fixture_markers.py.
|
protected |
Definition at line 306 of file fixture_markers.py.
|
protected |
Definition at line 207 of file fixture_markers.py.
|
protected |
Definition at line 262 of file fixture_markers.py.
| dict[str, I] get_infos | ( | pytest.FixtureRequest | request, |
| type[I] | info_type ) |
Return marked fixtures of info_type that are visible to a request.
Walks fixture definitions known to pytest, keeps those applicable to the requesting test, and skips fixtures whose scope is narrower than request.scope. Metadata is matched by its exact type, not subclasses. Discovery does not execute fixtures or require them to be test arguments.
The winning fixture definition is the one pytest would call. If it has no mark of info_type, the mark is inherited from the nearest overridden definition that has one. A mark on the winner replaces the inherited mark. There is no way to drop an inherited mark.
Fixtures within a single module are ordered by definition order. An override takes the position of the original fixture in that order — it is inserted in place of the fixture it overrides.
Fixtures from different modules follow the usual pytest definition-site priorities: non-conftest plugins (registration order), then conftest modules from outer to inner (less specific first, same as pytest override chains), then test modules, then test classes.
| request | The pytest fixture request object. |
| info_type | The info class whose tagged fixtures you want to look up. |
Definition at line 109 of file fixture_markers.py.
| Callable[..., object] mark | ( | Callable[..., object] | func, |
| object | info ) |
Attach info to the original function func.
Creates the marks dict if it is missing, otherwise updates it. The info type is the lookup key for pytest_userver.fixture_markers.get_infos. Each type may be attached at most once.
func must be the original function, not a @pytest.fixture wrapper. Apply the mark under @pytest.fixture.
| func | The original fixture function. |
| info | Metadata instance to store. |
Definition at line 64 of file fixture_markers.py.
|
protected |
Definition at line 46 of file fixture_markers.py.
|
protected |
Definition at line 44 of file fixture_markers.py.
|
protected |
Definition at line 45 of file fixture_markers.py.
|
protected |
Definition at line 47 of file fixture_markers.py.
| pytest_userver.fixture_markers.I = TypeVar('I') |
Definition at line 42 of file fixture_markers.py.
| pytest_userver.fixture_markers.is_visibility_more_specific = None |
Definition at line 35 of file fixture_markers.py.