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

Method __exit__

src/_pytest/raises.py:1398–1430  ·  view source on GitHub ↗
(
        self,
        exc_type: type[BaseException] | None,
        exc_val: BaseException | None,
        exc_tb: types.TracebackType | None,
    )

Source from the content-addressed store, hash-verified

1396 return False
1397
1398 def __exit__(
1399 self,
1400 exc_type: type[BaseException] | None,
1401 exc_val: BaseException | None,
1402 exc_tb: types.TracebackType | None,
1403 ) -> bool:
1404 __tracebackhide__ = True
1405 if exc_type is None:
1406 fail(f"DID NOT RAISE any exception, expected `{self.expected_type()}`")
1407
1408 assert self.excinfo is not None, (
1409 "Internal error - should have been constructed in __enter__"
1410 )
1411
1412 # group_str is the only thing that differs between RaisesExc and RaisesGroup...
1413 # I might just scrap it? Or make it part of fail_reason
1414 group_str = (
1415 "(group)"
1416 if self.allow_unwrapped and not issubclass(exc_type, BaseExceptionGroup)
1417 else "group"
1418 )
1419
1420 if not self.matches(exc_val):
1421 fail(f"Raised exception {group_str} did not match: {self._fail_reason}")
1422
1423 # Cast to narrow the exception type now that it's verified....
1424 # even though the TypeGuard in self.matches should be narrowing
1425 exc_info = cast(
1426 "tuple[type[BaseExceptionGroup[BaseExcT_co]], BaseExceptionGroup[BaseExcT_co], types.TracebackType]",
1427 (exc_type, exc_val, exc_tb),
1428 )
1429 self.excinfo.fill_unfilled(exc_info)
1430 return True
1431
1432 def expected_type(self) -> str:
1433 subexcs = []

Callers

nothing calls this directly

Calls 3

expected_typeMethod · 0.95
matchesMethod · 0.95
fill_unfilledMethod · 0.80

Tested by

no test coverage detected