Setup objects along the collector chain to the item.
(self, item: Item)
| 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. |
no test coverage detected