userver: pytest_userver.fixture_markers Namespace Reference
Loading...
Searching...
No Matches
pytest_userver.fixture_markers Namespace Reference

Detailed Description

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.

See also
Fixture markers

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

Function Documentation

◆ _cmp_from_lt()

int _cmp_from_lt ( Any a,
Any b )
protected

Definition at line 241 of file fixture_markers.py.

◆ _cmp_marked_fixtures()

int _cmp_marked_fixtures ( _MarkedFixture[Any] left,
_MarkedFixture[Any] right,
dict[str, int] plugin_key_order )
protected

Definition at line 245 of file fixture_markers.py.

◆ _cmp_sites()

int _cmp_sites ( pytest.FixtureDef[object] left,
pytest.FixtureDef[object] right )
protected

Definition at line 269 of file fixture_markers.py.

◆ _get_fixturedefs()

Sequence[pytest.FixtureDef[object]] | None _get_fixturedefs ( Any fixture_manager,
str name,
Any key )
protected

Definition at line 175 of file fixture_markers.py.

◆ _has_location()

bool _has_location ( pytest.FixtureDef[object] fixturedef)
protected

Definition at line 298 of file fixture_markers.py.

◆ _inherited_info()

I | None _inherited_info ( Sequence[pytest.FixtureDef[object]] matched,
type[I] info_type )
protected

Definition at line 229 of file fixture_markers.py.

◆ _is_nested_baseid()

bool _is_nested_baseid ( str prefix,
str full )
protected

Definition at line 302 of file fixture_markers.py.

◆ _is_pytest_fixture_wrapper()

bool _is_pytest_fixture_wrapper ( object func)
protected

Definition at line 169 of file fixture_markers.py.

◆ _iter_visible_fixtures()

Iterator[pytest.FixtureDef[object]] _iter_visible_fixtures ( pytest.FixtureRequest request,
Any key )
protected

Definition at line 183 of file fixture_markers.py.

◆ _legacy_more_specific()

bool _legacy_more_specific ( pytest.FixtureDef[object] candidate,
pytest.FixtureDef[object] other )
protected

Definition at line 281 of file fixture_markers.py.

◆ _mark_info()

I | None _mark_info ( pytest.FixtureDef[object] fixturedef,
type[I] info_type )
protected

Definition at line 306 of file fixture_markers.py.

◆ _marked_fixture_for_name()

_MarkedFixture[I] | None _marked_fixture_for_name ( pytest.FixtureRequest request,
str name,
type[I] info_type,
Any key )
protected

Definition at line 207 of file fixture_markers.py.

◆ _plugin_key()

str _plugin_key ( Any func)
protected

Definition at line 262 of file fixture_markers.py.

◆ get_infos()

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.

See also
Fixture markers
Parameters
requestThe pytest fixture request object.
info_typeThe info class whose tagged fixtures you want to look up.
Returns
dict[str, I] mapping each tagged fixture's name to the info object that was passed to pytest_userver.fixture_markers.mark. The dict is a fresh copy; mutating it has no effect on stored data.

Definition at line 109 of file fixture_markers.py.

◆ mark()

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.

See also
Fixture markers
Parameters
funcThe original fixture function.
infoMetadata instance to store.
Returns
func, unchanged.

Definition at line 64 of file fixture_markers.py.

Variable Documentation

◆ _mark_order_counter

pytest_userver.fixture_markers._mark_order_counter = itertools.count()
protected

Definition at line 46 of file fixture_markers.py.

◆ _MARKS_ATTR

str pytest_userver.fixture_markers._MARKS_ATTR = '_testsuite_fixture_marks'
protected

Definition at line 44 of file fixture_markers.py.

◆ _MARKS_ORDER_ATTR

str pytest_userver.fixture_markers._MARKS_ORDER_ATTR = '_testsuite_fixture_marks_order'
protected

Definition at line 45 of file fixture_markers.py.

◆ _SCOPE_RANK

dict pytest_userver.fixture_markers._SCOPE_RANK
protected
Initial value:
= {
'function': 0,
'class': 1,
'module': 2,
'package': 3,
'session': 4,
}

Definition at line 47 of file fixture_markers.py.

◆ I

pytest_userver.fixture_markers.I = TypeVar('I')

Definition at line 42 of file fixture_markers.py.

◆ is_visibility_more_specific

pytest_userver.fixture_markers.is_visibility_more_specific = None

Definition at line 35 of file fixture_markers.py.