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

Method test_error_messages_invalid_args

testing/python/approx.py:203–225  ·  view source on GitHub ↗
(self, assert_approx_raises_regex)

Source from the content-addressed store, hash-verified

201 )
202
203 def test_error_messages_invalid_args(self, assert_approx_raises_regex):
204 np = pytest.importorskip("numpy")
205 with pytest.raises(AssertionError) as e:
206 assert np.array([[1.2, 3.4], [4.0, 5.0]]) == pytest.approx(
207 np.array([[4.0], [5.0]])
208 )
209 message = "\n".join(str(e.value).split("\n")[1:])
210 assert message == "\n".join(
211 [
212 " Impossible to compare arrays with different shapes.",
213 " Shapes: (2, 1) and (2, 2)",
214 ]
215 )
216
217 with pytest.raises(AssertionError) as e:
218 assert [1.0, 2.0, 3.0] == pytest.approx([4.0, 5.0])
219 message = "\n".join(str(e.value).split("\n")[1:])
220 assert message == "\n".join(
221 [
222 " Impossible to compare lists with different sizes.",
223 " Lengths: 2 and 3",
224 ]
225 )
226
227 def test_error_messages_with_different_verbosity(self, assert_approx_raises_regex):
228 np = pytest.importorskip("numpy")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected