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

Method setup

src/_pytest/runner.py:482–501  ·  view source on GitHub ↗

Setup objects along the collector chain to the item.

(self, item: Item)

Source from the content-addressed store, hash-verified

480 ] = {}
481
482 def setup(self, item: Item) -> None:
483 """Setup objects along the collector chain to the item."""
484 needed_collectors = item.listchain()
485
486 # If a collector fails its setup, fail its entire subtree of items.
487 # The setup is not retried for each item - the same exception is used.
488 for col, (finalizers, exc) in self.stack.items():
489 assert col in needed_collectors, "previous item was not torn down properly"
490 if exc:
491 raise exc
492
493 for col in needed_collectors[len(self.stack) :]:
494 assert col not in self.stack
495 # Push onto the stack.
496 self.stack[col] = ([col.teardown], None)
497 try:
498 col.setup()
499 except TEST_OUTCOME as exc:
500 self.stack[col] = (self.stack[col][0], exc)
501 raise exc
502
503 def addfinalizer(self, finalizer: Callable[[], object], node: Node) -> None:
504 """Attach a finalizer to the given node.

Callers 1

pytest_runtest_setupFunction · 0.45

Calls 1

listchainMethod · 0.80

Tested by

no test coverage detected