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

Function test_raisesexc

testing/python/raises_group.py:1072–1120  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1070
1071
1072def test_raisesexc() -> None:
1073 with pytest.raises(
1074 ValueError,
1075 match=r"^You must specify at least one parameter to match on.$",
1076 ):
1077 RaisesExc() # type: ignore[call-overload]
1078 with pytest.raises(
1079 ValueError,
1080 match=wrap_escape("Expected a BaseException type, but got 'object'"),
1081 ):
1082 RaisesExc(object) # type: ignore[type-var]
1083
1084 with RaisesGroup(RaisesExc(ValueError)):
1085 raise ExceptionGroup("", (ValueError(),))
1086 with (
1087 fails_raises_group(
1088 "RaisesExc(TypeError): `ValueError()` is not an instance of `TypeError`"
1089 ),
1090 RaisesGroup(RaisesExc(TypeError)),
1091 ):
1092 raise ExceptionGroup("", (ValueError(),))
1093
1094 with RaisesExc(ValueError):
1095 raise ValueError
1096
1097 with pytest.raises(Failed, match=wrap_escape("DID NOT RAISE ValueError")):
1098 with RaisesExc(ValueError):
1099 ...
1100
1101 with pytest.raises(Failed, match=wrap_escape("DID NOT RAISE any exception")):
1102 with RaisesExc(match="foo"):
1103 ...
1104
1105 with pytest.raises(
1106 Failed,
1107 match=wrap_escape("DID NOT RAISE any of (ValueError, TypeError)"),
1108 ):
1109 with RaisesExc((ValueError, TypeError)):
1110 ...
1111
1112 # currently RaisesGroup says "Raised exception did not match" but RaisesExc doesn't...
1113 with pytest.raises(
1114 AssertionError,
1115 match=wrap_escape(
1116 "Regex pattern did not match.\n Expected regex: 'foo'\n Actual message: 'bar'"
1117 ),
1118 ):
1119 with RaisesExc(TypeError, match="foo"):
1120 raise TypeError("bar")
1121
1122
1123def test_raisesexc_match() -> None:

Callers

nothing calls this directly

Calls 4

RaisesExcClass · 0.90
RaisesGroupClass · 0.90
fails_raises_groupFunction · 0.85
wrap_escapeFunction · 0.70

Tested by

no test coverage detected