MCPcopy Index your code
hub / github.com/pytest-dev/pytest / test_incorrect_number_exceptions

Function test_incorrect_number_exceptions

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

Source from the content-addressed store, hash-verified

88
89
90def test_incorrect_number_exceptions() -> None:
91 # We previously gave an error saying the number of exceptions was wrong,
92 # but we now instead indicate excess/missing exceptions
93 with (
94 fails_raises_group(
95 "1 matched exception. Unexpected exception(s): [RuntimeError()]"
96 ),
97 RaisesGroup(ValueError),
98 ):
99 raise ExceptionGroup("", (RuntimeError(), ValueError()))
100
101 # will error if there's missing exceptions
102 with (
103 fails_raises_group(
104 "1 matched exception. Too few exceptions raised, found no match for: [SyntaxError]"
105 ),
106 RaisesGroup(ValueError, SyntaxError),
107 ):
108 raise ExceptionGroup("", (ValueError(),))
109
110 with (
111 fails_raises_group(
112 "\n"
113 "1 matched exception. \n"
114 "Too few exceptions raised!\n"
115 "The following expected exceptions did not find a match:\n"
116 " ValueError\n"
117 " It matches `ValueError()` which was paired with `ValueError`"
118 ),
119 RaisesGroup(ValueError, ValueError),
120 ):
121 raise ExceptionGroup("", (ValueError(),))
122
123 with (
124 fails_raises_group(
125 "\n"
126 "1 matched exception. \n"
127 "Unexpected exception(s)!\n"
128 "The following raised exceptions did not find a match\n"
129 " ValueError('b'):\n"
130 " It matches `ValueError` which was paired with `ValueError('a')`"
131 ),
132 RaisesGroup(ValueError),
133 ):
134 raise ExceptionGroup("", (ValueError("a"), ValueError("b")))
135
136 with (
137 fails_raises_group(
138 "\n"
139 "1 matched exception. \n"
140 "The following expected exceptions did not find a match:\n"
141 " ValueError\n"
142 " It matches `ValueError()` which was paired with `ValueError`\n"
143 "The following raised exceptions did not find a match\n"
144 " SyntaxError():\n"
145 " `SyntaxError()` is not an instance of `ValueError`"
146 ),
147 RaisesGroup(ValueError, ValueError),

Callers

nothing calls this directly

Calls 2

RaisesGroupClass · 0.90
fails_raises_groupFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…