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

Class FixtureManager

src/_pytest/fixtures.py:1388–1686  ·  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

1386
1387
1388class FixtureManager:
1389 """pytest fixture definitions and information is stored and managed
1390 from this class.
1391
1392 During collection fm.parsefactories() is called multiple times to parse
1393 fixture function definitions into FixtureDef objects and internal
1394 data structures.
1395
1396 During collection of test functions, metafunc-mechanics instantiate
1397 a FuncFixtureInfo object which is cached per node/func-name.
1398 This FuncFixtureInfo object is later retrieved by Function nodes
1399 which themselves offer a fixturenames attribute.
1400
1401 The FuncFixtureInfo object holds information about fixtures and FixtureDefs
1402 relevant for a particular function. An initial list of fixtures is
1403 assembled like this:
1404
1405 - ini-defined usefixtures
1406 - autouse-marked fixtures along the collection chain up from the function
1407 - usefixtures markers at module/class/function level
1408 - test function funcargs
1409
1410 Subsequently the funcfixtureinfo.fixturenames attribute is computed
1411 as the closure of the fixtures needed to setup the initial fixtures,
1412 i.e. fixtures needed by fixture functions themselves are appended
1413 to the fixturenames list.
1414
1415 Upon the test-setup phases all fixturenames are instantiated, retrieved
1416 by a lookup of their FuncFixtureInfo.
1417 """
1418
1419 FixtureLookupError = FixtureLookupError
1420 FixtureLookupErrorRepr = FixtureLookupErrorRepr
1421
1422 def __init__(self, session: "Session") -> None:
1423 self.session = session
1424 self.config: Config = session.config
1425 self._arg2fixturedefs: Dict[str, List[FixtureDef[Any]]] = {}
1426 self._holderobjseen: Set[object] = set()
1427 # A mapping from a nodeid to a list of autouse fixtures it defines.
1428 self._nodeid_autousenames: Dict[str, List[str]] = {
1429 "": self.config.getini("usefixtures"),
1430 }
1431 session.config.pluginmanager.register(self, "funcmanage")
1432
1433 def _get_direct_parametrize_args(self, node: nodes.Node) -> List[str]:
1434 """Return all direct parametrization arguments of a node, so we don't
1435 mistake them for fixtures.
1436
1437 Check https://github.com/pytest-dev/pytest/issues/5036.
1438
1439 These things are done later as well when dealing with parametrization
1440 so this could be improved.
1441 """
1442 parametrize_argnames: List[str] = []
1443 for marker in node.iter_markers(name="parametrize"):
1444 if not marker.kwargs.get("indirect", False):
1445 p_argnames, _ = ParameterSet._parse_parametrize_args(

Callers 2

make_functionMethod · 0.90
pytest_sessionstartFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected