MCPcopy Create free account
hub / github.com/pytest-dev/pytest / _getscopeitem

Method _getscopeitem

src/_pytest/fixtures.py:735–755  ·  view source on GitHub ↗
(
        self, scope: Union[Scope, "_ScopeName"]
    )

Source from the content-addressed store, hash-verified

733 return lines
734
735 def _getscopeitem(
736 self, scope: Union[Scope, "_ScopeName"]
737 ) -> Union[nodes.Item, nodes.Collector]:
738 if isinstance(scope, str):
739 scope = Scope(scope)
740 if scope is Scope.Function:
741 # This might also be a non-function Item despite its attribute name.
742 node: Optional[Union[nodes.Item, nodes.Collector]] = self._pyfuncitem
743 elif scope is Scope.Package:
744 # FIXME: _fixturedef is not defined on FixtureRequest (this class),
745 # but on FixtureRequest (a subclass).
746 node = get_scope_package(self._pyfuncitem, self._fixturedef) # type: ignore[attr-defined]
747 else:
748 node = get_scope_node(self._pyfuncitem, scope)
749 if node is None and scope is Scope.Class:
750 # Fallback to function item itself.
751 node = self._pyfuncitem
752 assert node, 'Could not obtain a node for scope "{}" for function {!r}'.format(
753 scope, self._pyfuncitem
754 )
755 return node
756
757 def __repr__(self) -> str:
758 return "<FixtureRequest for %r>" % (self.node)

Callers 2

nodeMethod · 0.95
_addfinalizerMethod · 0.95

Calls 4

ScopeClass · 0.90
get_scope_packageFunction · 0.85
get_scope_nodeFunction · 0.85
formatMethod · 0.45

Tested by

no test coverage detected