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

Class FuncFixtureInfo

src/_pytest/fixtures.py:390–437  ·  view source on GitHub ↗

Fixture-related information for a fixture-requesting item (e.g. test function). This is used to examine the fixtures which an item requests statically (known during collection). This includes autouse fixtures, fixtures requested by the `usefixtures` marker, fixtures requested in the

Source from the content-addressed store, hash-verified

388
389@dataclasses.dataclass(frozen=True)
390class FuncFixtureInfo:
391 """Fixture-related information for a fixture-requesting item (e.g. test
392 function).
393
394 This is used to examine the fixtures which an item requests statically
395 (known during collection). This includes autouse fixtures, fixtures
396 requested by the `usefixtures` marker, fixtures requested in the function
397 parameters, and the transitive closure of these.
398
399 An item may also request fixtures dynamically (using `request.getfixturevalue`);
400 these are not reflected here.
401 """
402
403 __slots__ = ("argnames", "initialnames", "name2fixturedefs", "names_closure")
404
405 # Fixture names that the item requests directly by function parameters.
406 argnames: tuple[str, ...]
407 # Fixture names that the item immediately requires. These include
408 # argnames + fixture names specified via usefixtures and via autouse=True in
409 # fixture definitions.
410 initialnames: tuple[str, ...]
411 # The transitive closure of the fixture names that the item requires.
412 # Note: can't include dynamic dependencies (`request.getfixturevalue` calls).
413 names_closure: list[str]
414 # A map from a fixture name in the transitive closure to the FixtureDefs
415 # matching the name which are applicable to this function.
416 # There may be multiple overriding fixtures with the same name. The
417 # sequence is ordered from furthest to closes to the function.
418 name2fixturedefs: dict[str, Sequence[FixtureDef[Any]]]
419
420 def prune_dependency_tree(self) -> None:
421 """Recompute names_closure from initialnames and name2fixturedefs.
422
423 Can only reduce names_closure, which means that the new closure will
424 always be a subset of the old one. The order is preserved.
425
426 This method is needed because direct parametrization may shadow some
427 of the fixtures that were included in the originally built dependency
428 tree. In this way the dependency tree can get pruned, and the closure
429 of argnames may get reduced.
430 """
431 closure = set(
432 traverse_fixture_closure(
433 self.initialnames,
434 getfixturedefs=self.name2fixturedefs.get,
435 )
436 )
437 self.names_closure[:] = (name for name in self.names_closure if name in closure)
438
439
440class FixtureRequest(abc.ABC):

Callers 1

getfixtureinfoMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected