MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_raises_match

Method test_raises_match

testing/python/raises.py:184–213  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

182 assert refcount == len(gc.get_referrers(t))
183
184 def test_raises_match(self) -> None:
185 msg = r"with base \d+"
186 with pytest.raises(ValueError, match=msg):
187 int("asdf")
188
189 msg = "with base 10"
190 with pytest.raises(ValueError, match=msg):
191 int("asdf")
192
193 msg = "with base 16"
194 expr = "Regex pattern {!r} does not match \"invalid literal for int() with base 10: 'asdf'\".".format(
195 msg
196 )
197 with pytest.raises(AssertionError, match=re.escape(expr)):
198 with pytest.raises(ValueError, match=msg):
199 int("asdf", base=10)
200
201 # "match" without context manager.
202 pytest.raises(ValueError, int, "asdf").match("invalid literal")
203 with pytest.raises(AssertionError) as excinfo:
204 pytest.raises(ValueError, int, "asdf").match(msg)
205 assert str(excinfo.value) == expr
206
207 pytest.raises(TypeError, int, match="invalid")
208
209 def tfunc(match):
210 raise ValueError(f"match={match}")
211
212 pytest.raises(ValueError, tfunc, match="asdf").match("match=asdf")
213 pytest.raises(ValueError, tfunc, match="").match("match=")
214
215 def test_match_failure_string_quoting(self):
216 with pytest.raises(AssertionError) as excinfo:

Callers

nothing calls this directly

Calls 3

intClass · 0.85
matchMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected