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

Method _check_expected

src/_pytest/raises.py:1216–1232  ·  view source on GitHub ↗

Helper method for `RaisesGroup.matches` and `RaisesGroup._check_exceptions` to check one of potentially several expected exceptions.

(
        expected_type: (
            type[BaseException] | RaisesExc[BaseException] | RaisesGroup[BaseException]
        ),
        exception: BaseException,
    )

Source from the content-addressed store, hash-verified

1214
1215 @staticmethod
1216 def _check_expected(
1217 expected_type: (
1218 type[BaseException] | RaisesExc[BaseException] | RaisesGroup[BaseException]
1219 ),
1220 exception: BaseException,
1221 ) -> str | None:
1222 """Helper method for `RaisesGroup.matches` and `RaisesGroup._check_exceptions`
1223 to check one of potentially several expected exceptions."""
1224 if isinstance(expected_type, type):
1225 return _check_raw_type(expected_type, exception)
1226 res = expected_type.matches(exception)
1227 if res:
1228 return None
1229 assert expected_type.fail_reason is not None
1230 if expected_type.fail_reason.startswith("\n"):
1231 return f"\n{expected_type!r}: {indent(expected_type.fail_reason, ' ')}"
1232 return f"{expected_type!r}: {expected_type.fail_reason}"
1233
1234 @staticmethod
1235 def _repr_expected(e: type[BaseException] | AbstractRaises[BaseException]) -> str:

Callers 2

matchesMethod · 0.95
_check_exceptionsMethod · 0.95

Calls 2

_check_raw_typeFunction · 0.85
matchesMethod · 0.45

Tested by

no test coverage detected