A container for a factory definition.
| 964 | |
| 965 | @final |
| 966 | class FixtureDef(Generic[FixtureValue]): |
| 967 | """A container for a factory definition.""" |
| 968 | |
| 969 | def __init__( |
| 970 | self, |
| 971 | fixturemanager: "FixtureManager", |
| 972 | baseid: Optional[str], |
| 973 | argname: str, |
| 974 | func: "_FixtureFunc[FixtureValue]", |
| 975 | scope: Union[Scope, "_ScopeName", Callable[[str, Config], "_ScopeName"], None], |
| 976 | params: Optional[Sequence[object]], |
| 977 | unittest: bool = False, |
| 978 | ids: Optional[ |
| 979 | Union[ |
| 980 | Tuple[Union[None, str, float, int, bool], ...], |
| 981 | Callable[[Any], Optional[object]], |
| 982 | ] |
| 983 | ] = None, |
| 984 | ) -> None: |
| 985 | self._fixturemanager = fixturemanager |
| 986 | self.baseid = baseid or "" |
| 987 | self.has_location = baseid is not None |
| 988 | self.func = func |
| 989 | self.argname = argname |
| 990 | if scope is None: |
| 991 | scope = Scope.Function |
| 992 | elif callable(scope): |
| 993 | scope = _eval_scope_callable(scope, argname, fixturemanager.config) |
| 994 | |
| 995 | if isinstance(scope, str): |
| 996 | scope = Scope.from_user( |
| 997 | scope, descr=f"Fixture '{func.__name__}'", where=baseid |
| 998 | ) |
| 999 | self._scope = scope |
| 1000 | self.params: Optional[Sequence[object]] = params |
| 1001 | self.argnames: Tuple[str, ...] = getfuncargnames( |
| 1002 | func, name=argname, is_method=unittest |
| 1003 | ) |
| 1004 | self.unittest = unittest |
| 1005 | self.ids = ids |
| 1006 | self.cached_result: Optional[_FixtureCachedResult[FixtureValue]] = None |
| 1007 | self._finalizers: List[Callable[[], object]] = [] |
| 1008 | |
| 1009 | @property |
| 1010 | def scope(self) -> "_ScopeName": |
| 1011 | """Scope string, one of "function", "class", "module", "package", "session".""" |
| 1012 | return self._scope.value |
| 1013 | |
| 1014 | def addfinalizer(self, finalizer: Callable[[], object]) -> None: |
| 1015 | self._finalizers.append(finalizer) |
| 1016 | |
| 1017 | def finish(self, request: SubRequest) -> None: |
| 1018 | exc = None |
| 1019 | try: |
| 1020 | while self._finalizers: |
| 1021 | try: |
| 1022 | func = self._finalizers.pop() |
| 1023 | func() |
no outgoing calls
no test coverage detected