Skip to content

Commit 7c7b16b

Browse files
[refactor] Drop the two continues in callbinrepr
Nest the truthiness checks instead of using ``continue`` to skip to the next ``hook_result`` entry. Behaviourally identical, but each ``continue`` was being reported as a partial branch by codecov even when both arcs were hit by tests — pytester-driven in-process tests don't always show the ``continue → loop exit`` arc, so the partials were sticky. With the nested form the for-loop has a single fall- through edge and the partial disappears. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 5c0c0f8 commit 7c7b16b

1 file changed

Lines changed: 11 additions & 11 deletions

File tree

src/_pytest/assertion/__init__.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,19 +181,19 @@ def callbinrepr(op, left: object, right: object) -> str | None:
181181
config=item.config, op=op, left=left, right=right
182182
)
183183
for new_expl in hook_result:
184-
if not new_expl:
185-
continue
186184
# Plugin-supplied lists are truncated here; the built-in
187185
# impl truncates as it streams, so this is a no-op on its
188-
# already-short output.
189-
new_expl = truncate.materialize_with_truncation(new_expl, item.config)
190-
if not new_expl:
191-
continue
192-
new_expl = [line.replace("\n", "\\n") for line in new_expl]
193-
res = "\n~".join(new_expl)
194-
if item.config.getvalue("assertmode") == "rewrite":
195-
res = res.replace("%", "%%")
196-
return res
186+
# already-short output. ``materialize_with_truncation`` can
187+
# return ``[]`` when the input was a truthy-but-empty
188+
# iterable, so re-check after materialising.
189+
if new_expl:
190+
new_expl = truncate.materialize_with_truncation(new_expl, item.config)
191+
if new_expl:
192+
new_expl = [line.replace("\n", "\\n") for line in new_expl]
193+
res = "\n~".join(new_expl)
194+
if item.config.getvalue("assertmode") == "rewrite":
195+
res = res.replace("%", "%%")
196+
return res
197197
return None
198198

199199
saved_assert_hooks = util._reprcompare, util._assertion_pass

0 commit comments

Comments
 (0)