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

Function do_assert

testing/python/approx.py:59–86  ·  view source on GitHub ↗
(lhs, rhs, expected_message, verbosity_level=0)

Source from the content-addressed store, hash-verified

57@pytest.fixture
58def assert_approx_raises_regex(pytestconfig):
59 def do_assert(lhs, rhs, expected_message, verbosity_level=0):
60 import re
61
62 with temporary_verbosity(pytestconfig, verbosity_level):
63 with pytest.raises(AssertionError) as e:
64 assert lhs == approx(rhs)
65
66 nl = "\n"
67 obtained_message = str(e.value).splitlines()[1:]
68 assert len(obtained_message) == len(expected_message), (
69 "Regex message length doesn't match obtained.\n"
70 "Obtained:\n"
71 f"{nl.join(obtained_message)}\n\n"
72 "Expected regex:\n"
73 f"{nl.join(expected_message)}\n\n"
74 )
75
76 for i, (obtained_line, expected_line) in enumerate(
77 zip(obtained_message, expected_message)
78 ):
79 regex = re.compile(expected_line)
80 assert regex.match(obtained_line) is not None, (
81 "Unexpected error message:\n"
82 f"{nl.join(obtained_message)}\n\n"
83 "Did not match regex:\n"
84 f"{nl.join(expected_message)}\n\n"
85 f"With verbosity level = {verbosity_level}, on line {i}"
86 )
87
88 return do_assert
89

Callers

nothing calls this directly

Calls 4

approxFunction · 0.90
temporary_verbosityFunction · 0.85
compileMethod · 0.80
matchMethod · 0.80

Tested by

no test coverage detected