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

Function do_assert

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…