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

Method setup

src/_pytest/runner.py:520–539  ·  view source on GitHub ↗

Setup objects along the collector chain to the item.

(self, item: Item)

Source from the content-addressed store, hash-verified

518 return node in self.stack
519
520 def setup(self, item: Item) -> None:
521 """Setup objects along the collector chain to the item."""
522 needed_collectors = item.listchain()
523
524 # If a collector fails its setup, fail its entire subtree of items.
525 # The setup is not retried for each item - the same exception is used.
526 for col, (finalizers, exc) in self.stack.items():
527 assert col in needed_collectors, "previous item was not torn down properly"
528 if exc:
529 raise exc[0].with_traceback(exc[1])
530
531 for col in needed_collectors[len(self.stack) :]:
532 assert col not in self.stack
533 # Push onto the stack.
534 self.stack[col] = ([col.teardown], None)
535 try:
536 col.setup()
537 except TEST_OUTCOME as exc:
538 self.stack[col] = (self.stack[col][0], (exc, exc.__traceback__))
539 raise
540
541 def addfinalizer(self, finalizer: Callable[[], object], node: Node) -> None:
542 """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