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

Class FixtureManager

src/_pytest/fixtures.py:1683–2169  ·  view source on GitHub ↗

pytest fixture definitions and information is stored and managed from this class. During collection fm.parsefactories() is called multiple times to parse fixture function definitions into FixtureDef objects and internal data structures. During collection of test functions, meta

Source from the content-addressed store, hash-verified

1681
1682
1683class FixtureManager:
1684 """pytest fixture definitions and information is stored and managed
1685 from this class.
1686
1687 During collection fm.parsefactories() is called multiple times to parse
1688 fixture function definitions into FixtureDef objects and internal
1689 data structures.
1690
1691 During collection of test functions, metafunc-mechanics instantiate
1692 a FuncFixtureInfo object which is cached per node/func-name.
1693 This FuncFixtureInfo object is later retrieved by Function nodes
1694 which themselves offer a fixturenames attribute.
1695
1696 The FuncFixtureInfo object holds information about fixtures and FixtureDefs
1697 relevant for a particular function. An initial list of fixtures is
1698 assembled like this:
1699
1700 - config-defined usefixtures
1701 - autouse-marked fixtures along the collection chain up from the function
1702 - usefixtures markers at module/class/function level
1703 - test function funcargs
1704
1705 Subsequently the funcfixtureinfo.fixturenames attribute is computed
1706 as the closure of the fixtures needed to setup the initial fixtures,
1707 i.e. fixtures needed by fixture functions themselves are appended
1708 to the fixturenames list.
1709
1710 Upon the test-setup phases all fixturenames are instantiated, retrieved
1711 by a lookup of their FuncFixtureInfo.
1712 """
1713
1714 def __init__(self, session: Session) -> None:
1715 self.session = session
1716 self.config: Config = session.config
1717 # Maps a fixture name (argname) to all of the FixtureDefs in the test
1718 # suite/plugins defined with this name. Populated by parsefactories().
1719 # TODO: The order of the FixtureDefs list of each arg is significant,
1720 # explain.
1721 self._arg2fixturedefs: Final[dict[str, list[FixtureDef[Any]]]] = {}
1722 # A mapping from a node to a list of autouse fixture names it defines.
1723 # The Session entry holds global usefixtures from config.
1724 self._node_autousenames: Final[dict[nodes.Node, list[str]]] = {
1725 session: list(self.config.getini("usefixtures")),
1726 }
1727 # Legacy fallback: nodeid string -> autouse names, for plugins still
1728 # using the deprecated nodeid-based API without a node reference.
1729 self._nodeid_autousenames: Final[dict[str, list[str]]] = {}
1730 # Pending conftest modules waiting to be parsed when their Directory is collected.
1731 # Maps directory path -> conftest plugin module.
1732 self._pending_conftests: Final[dict[Path, object]] = {}
1733 session.config.pluginmanager.register(self, "funcmanage")
1734 # Flush initial conftests from directories above rootpath immediately.
1735 # These will never get a Directory collector, so they need Session scope.
1736 # This must happen here (not in pytest_make_collect_report) because
1737 # collection may fail before Session collection starts (e.g. bad args).
1738 self._flush_pending_conftests_to_session(session)
1739
1740 def getfixtureinfo(

Callers 2

make_functionMethod · 0.90
pytest_sessionstartFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected