MCPcopy
hub / github.com/pytest-dev/pytest / __init__

Method __init__

src/_pytest/fixtures.py:1057–1131  ·  view source on GitHub ↗
(
        self,
        config: Config,
        baseid: str | None | NotSetType,
        argname: str,
        func: _FixtureFunc[FixtureValue],
        scope: Scope | ScopeName | Callable[[str, Config], ScopeName] | None,
        params: Sequence[object] | None,
        ids: tuple[object | None, ...] | Callable[[Any], object | None] | None = None,
        *,
        node: nodes.Node | NotSetType = NOTSET,
        # only used in a deprecationwarning msg, can be removed in pytest9
        _autouse: bool = False,
        _ispytest: bool = False,
    )

Source from the content-addressed store, hash-verified

1055 """
1056
1057 def __init__(
1058 self,
1059 config: Config,
1060 baseid: str | None | NotSetType,
1061 argname: str,
1062 func: _FixtureFunc[FixtureValue],
1063 scope: Scope | ScopeName | Callable[[str, Config], ScopeName] | None,
1064 params: Sequence[object] | None,
1065 ids: tuple[object | None, ...] | Callable[[Any], object | None] | None = None,
1066 *,
1067 node: nodes.Node | NotSetType = NOTSET,
1068 # only used in a deprecationwarning msg, can be removed in pytest9
1069 _autouse: bool = False,
1070 _ispytest: bool = False,
1071 ) -> None:
1072 check_ispytest(_ispytest)
1073 # Emit deprecation warning if deprecated baseid string is used.
1074 if node is NOTSET:
1075 warnings.warn(FIXTURE_BASEID_DEPRECATED, stacklevel=2)
1076 if baseid is NOTSET:
1077 baseid = None
1078 # The node where this fixture was defined, if available.
1079 # Used for node-based matching which is more robust than string matching.
1080 self.node: Final = node if node is not NOTSET else None
1081 # The "base" node ID for the fixture.
1082 #
1083 # This is a node ID prefix. A fixture is only available to a node (e.g.
1084 # a `Function` item) if the fixture's baseid is a nodeid of a parent of
1085 # node.
1086 #
1087 # For a fixture found in a Collector's object (e.g. a `Module`s module,
1088 # a `Class`'s class), the baseid is the Collector's nodeid.
1089 #
1090 # For a fixture found in a conftest plugin, the baseid is the conftest's
1091 # directory path relative to the rootdir.
1092 #
1093 # For other plugins, the baseid is the empty string (always matches).
1094 # When node is available, baseid is derived from node.nodeid.
1095 #
1096 # Deprecated: replaced by ``node``.
1097 self.baseid: Final = node.nodeid if node is not NOTSET else (baseid or "")
1098 # Whether the fixture was found from a node or a conftest in the
1099 # collection tree. Will be false for fixtures defined in non-conftest
1100 # plugins.
1101 #
1102 # Deprecated: kept only to back the deprecated ``has_location`` property.
1103 self._has_location: Final = node is not NOTSET or baseid is not None
1104 # The fixture factory function.
1105 self.func: Final = func
1106 # The name by which the fixture may be requested.
1107 self.argname: Final = argname
1108 if scope is None:
1109 scope = Scope.Function
1110 elif callable(scope):
1111 scope = _eval_scope_callable(scope, argname, config)
1112 if isinstance(scope, str):
1113 scope = Scope.from_user(
1114 scope, descr=f"Fixture '{func.__name__}'", where=self.baseid

Callers

nothing calls this directly

Calls 5

check_ispytestFunction · 0.90
getfuncargnamesFunction · 0.90
_eval_scope_callableFunction · 0.85
from_userMethod · 0.80
warnMethod · 0.45

Tested by

no test coverage detected