Teardown the current stack up until reaching nodes that nextitem also descends from. When nextitem is None (meaning we're at the last item), the entire stack is torn down.
(self, nextitem: Optional[Item])
| 511 | self.stack[node][0].append(finalizer) |
| 512 | |
| 513 | def teardown_exact(self, nextitem: Optional[Item]) -> None: |
| 514 | """Teardown the current stack up until reaching nodes that nextitem |
| 515 | also descends from. |
| 516 | |
| 517 | When nextitem is None (meaning we're at the last item), the entire |
| 518 | stack is torn down. |
| 519 | """ |
| 520 | needed_collectors = nextitem and nextitem.listchain() or [] |
| 521 | exc = None |
| 522 | while self.stack: |
| 523 | if list(self.stack.keys()) == needed_collectors[: len(self.stack)]: |
| 524 | break |
| 525 | node, (finalizers, _) = self.stack.popitem() |
| 526 | while finalizers: |
| 527 | fin = finalizers.pop() |
| 528 | try: |
| 529 | fin() |
| 530 | except TEST_OUTCOME as e: |
| 531 | # XXX Only first exception will be seen by user, |
| 532 | # ideally all should be reported. |
| 533 | if exc is None: |
| 534 | exc = e |
| 535 | if exc: |
| 536 | raise exc |
| 537 | if nextitem is None: |
| 538 | assert not self.stack |
| 539 | |
| 540 | |
| 541 | def collect_one_node(collector: Collector) -> CollectReport: |