Register a fixture :param name: The fixture's name. :param func: The fixture's implementation function. :param nodeid: The visibility of the fixture (deprecated, use node instead). The fixture will be available to the node with
(
self,
*,
name: str,
func: _FixtureFunc[object],
nodeid: str | None | NotSetType = NOTSET,
scope: 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,
node: nodes.Node | NotSetType = NOTSET,
)
| 1947 | items[:] = reorder_items(items) |
| 1948 | |
| 1949 | def _register_fixture( |
| 1950 | self, |
| 1951 | *, |
| 1952 | name: str, |
| 1953 | func: _FixtureFunc[object], |
| 1954 | nodeid: str | None | NotSetType = NOTSET, |
| 1955 | scope: Scope | ScopeName | Callable[[str, Config], ScopeName] = class="st">"function", |
| 1956 | params: Sequence[object] | None = None, |
| 1957 | ids: tuple[object | None, ...] | Callable[[Any], object | None] | None = None, |
| 1958 | autouse: bool = False, |
| 1959 | node: nodes.Node | NotSetType = NOTSET, |
| 1960 | ) -> None: |
| 1961 | class="st">"""Register a fixture |
| 1962 | |
| 1963 | :param name: |
| 1964 | The fixture&class="cm">#x27;s name. |
| 1965 | :param func: |
| 1966 | The fixture&class="cm">#x27;s implementation function. |
| 1967 | :param nodeid: |
| 1968 | The visibility of the fixture (deprecated, use node instead). |
| 1969 | The fixture will be available to the node with this nodeid and |
| 1970 | its children in the collection tree. None means global visibility. |
| 1971 | :param node: |
| 1972 | The node where the fixture is defined (preferred over nodeid). |
| 1973 | When provided, enables node-based matching which is more robust. |
| 1974 | :param scope: |
| 1975 | The fixture&class="cm">#x27;s scope. |
| 1976 | :param params: |
| 1977 | The fixture&class="cm">#x27;s parametrization params. |
| 1978 | :param ids: |
| 1979 | The fixture&class="cm">#x27;s IDs. |
| 1980 | :param autouse: |
| 1981 | Whether this is an autouse fixture. |
| 1982 | class="st">""" |
| 1983 | class="cm"># Emit deprecation warning if nodeid string. |
| 1984 | if nodeid is not NOTSET or node is NOTSET: |
| 1985 | warnings.warn(FIXTURE_NODEID_DEPRECATED, stacklevel=2) |
| 1986 | fixture_def = FixtureDef( |
| 1987 | config=self.config, |
| 1988 | baseid=nodeid, |
| 1989 | argname=name, |
| 1990 | func=func, |
| 1991 | scope=scope, |
| 1992 | params=params, |
| 1993 | ids=ids, |
| 1994 | _ispytest=True, |
| 1995 | _autouse=autouse, |
| 1996 | node=node, |
| 1997 | ) |
| 1998 | |
| 1999 | faclist = self._arg2fixturedefs.setdefault(name, []) |
| 2000 | class="cm"># Insert the fixturedef into the list while maintaining a partial order |
| 2001 | class="cm"># based on visibility: a fixturedef whose visibility is more specific |
| 2002 | class="cm"># sorts after a more general one, so that it takes precedence in the |
| 2003 | class="cm"># override chain (the last applicable fixturedef in the list is used |
| 2004 | class="cm"># first, see getfixturedefs). |
| 2005 | class="cm"># fixturedefs with the same visibility keep registration order, i.e. the |
| 2006 | class="cm"># last registered wins. |
no test coverage detected