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

Function callbinrepr

src/_pytest/assertion/__init__.py:165–191  ·  view source on GitHub ↗

Call the pytest_assertrepr_compare hook and prepare the result. This uses the first result from the hook and then ensures the following: * Overly verbose explanations are truncated unless configured otherwise (eg. if running in verbose mode). * Embedded new

(op, left: object, right: object)

Source from the content-addressed store, hash-verified

163 ihook = item.ihook
164
165 def callbinrepr(op, left: object, right: object) -> str | None:
166 """Call the pytest_assertrepr_compare hook and prepare the result.
167
168 This uses the first result from the hook and then ensures the
169 following:
170 * Overly verbose explanations are truncated unless configured otherwise
171 (eg. if running in verbose mode).
172 * Embedded newlines are escaped to help util.format_explanation()
173 later.
174 * If the rewrite mode is used embedded %-characters are replaced
175 to protect later % formatting.
176
177 The result can be formatted by util.format_explanation() for
178 pretty printing.
179 """
180 hook_result = ihook.pytest_assertrepr_compare(
181 config=item.config, op=op, left=left, right=right
182 )
183 for new_expl in hook_result:
184 if new_expl:
185 new_expl = truncate.truncate_if_required(new_expl, item)
186 new_expl = [line.replace("\n", "\\n") for line in new_expl]
187 res = "\n~".join(new_expl)
188 if item.config.getvalue("assertmode") == "rewrite":
189 res = res.replace("%", "%%")
190 return res
191 return None
192
193 saved_assert_hooks = util._reprcompare, util._assertion_pass
194 util._reprcompare = callbinrepr

Callers

nothing calls this directly

Calls 2

joinMethod · 0.80
getvalueMethod · 0.45

Tested by

no test coverage detected