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

Class SubRequest

src/_pytest/fixtures.py:813–896  ·  view source on GitHub ↗

The type of the ``request`` fixture in a fixture function requested (transitively) by a test function.

Source from the content-addressed store, hash-verified

811
812@final
813class SubRequest(FixtureRequest):
814 """The type of the ``request`` fixture in a fixture function requested
815 (transitively) by a test function."""
816
817 def __init__(
818 self,
819 request: FixtureRequest,
820 scope: Scope,
821 param: Any,
822 param_index: int,
823 fixturedef: FixtureDef[object],
824 *,
825 _ispytest: bool = False,
826 ) -> None:
827 super().__init__(
828 pyfuncitem=request._pyfuncitem,
829 fixturename=fixturedef.argname,
830 fixture_defs=request._fixture_defs,
831 arg2fixturedefs=request._arg2fixturedefs,
832 _ispytest=_ispytest,
833 )
834 self._parent_request: Final[FixtureRequest] = request
835 self._fixturedef: Final[FixtureDef[object]] = fixturedef
836 if param is not NOTSET:
837 self.param = param
838 self.param_index: Final = param_index
839 self._scope_field: Final = scope
840 if scope is Scope.Function:
841 # This might also be a non-function Item despite its attribute name.
842 node: nodes.Node | None = self._pyfuncitem
843 elif scope is Scope.Package:
844 node = get_scope_package(self._pyfuncitem, self._fixturedef)
845 else:
846 node = get_scope_node(self._pyfuncitem, scope)
847 if node is None and scope is Scope.Class:
848 # Fallback to function item itself.
849 node = self._pyfuncitem
850 assert node, (
851 f'Could not obtain a node for scope "{scope}" for function {self._pyfuncitem!r}'
852 )
853 self._node: Final = node
854
855 def __repr__(self) -> str:
856 return f"<SubRequest {self.fixturename!r} for {self._pyfuncitem!r}>"
857
858 @property
859 def _scope(self) -> Scope:
860 return self._scope_field
861
862 @property
863 def node(self):
864 return self._node
865
866 def _check_scope(
867 self,
868 requested_fixturedef: FixtureDef[object],
869 requested_scope: Scope,
870 ) -> None:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected