(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: types.TracebackType | None,
)
| 686 | |
| 687 | # TODO: move common code into superclass |
| 688 | def __exit__( |
| 689 | self, |
| 690 | exc_type: type[BaseException] | None, |
| 691 | exc_val: BaseException | None, |
| 692 | exc_tb: types.TracebackType | None, |
| 693 | ) -> bool: |
| 694 | __tracebackhide__ = True |
| 695 | if exc_type is None: |
| 696 | if not self.expected_exceptions: |
| 697 | fail("DID NOT RAISE any exception") |
| 698 | if len(self.expected_exceptions) == 1: |
| 699 | fail(f"DID NOT RAISE {self.expected_exceptions[0].__name__}") |
| 700 | else: |
| 701 | names = ", ".join(x.__name__ for x in self.expected_exceptions) |
| 702 | fail(f"DID NOT RAISE any of ({names})") |
| 703 | |
| 704 | assert self.excinfo is not None, ( |
| 705 | "Internal error - should have been constructed in __enter__" |
| 706 | ) |
| 707 | |
| 708 | if not self.matches(exc_val): |
| 709 | if self._just_propagate: |
| 710 | return False |
| 711 | raise AssertionError(self._fail_reason) from None |
| 712 | |
| 713 | # Cast to narrow the exception type now that it's verified.... |
| 714 | # even though the TypeGuard in self.matches should be narrowing |
| 715 | exc_info = cast( |
| 716 | "tuple[type[BaseExcT_co_default], BaseExcT_co_default, types.TracebackType]", |
| 717 | (exc_type, exc_val, exc_tb), |
| 718 | ) |
| 719 | self.excinfo.fill_unfilled(exc_info) |
| 720 | return True |
| 721 | |
| 722 | |
| 723 | @final |
nothing calls this directly
no test coverage detected