Skip to content

-v hint shown in raises diff, but verbosity not propagated in raises.py #14214

@ananya4khandelwal

Description

@ananya4khandelwal

Hi,

While investigating pytest.raises(..., match=...) diff behavior, I noticed that when the assertion diff truncates identical leading characters, the output includes the hint:

Skipping XX identical leading characters in diff, use -v to show

However, running with -v or -vv produces identical output -- verbosity does not seem to affect this code path.

Minimal Reproducer

import pytest, re

def test_raises_v_hint_broken():
    prefix = "A" * 60
    expected = prefix + " expected_ending"
    actual = prefix + " actual_ending"

    with pytest.raises(ValueError, match=f"^{re.escape(expected)}$"):
        raise ValueError(actual)

Running this produces:

AssertionError: Skipping 51 identical leading characters in diff, use -v to show

Running with -v or -vv produces identical output.

Observations

It appears _check_match() calls _diff_text() with the default verbosity (verbose=0), and verbosity from the pytest config is not propagated. _diff_text() does respect verbosity >= 1, but it never receives it in this path.

There is also a TODO in the code noting uncertainty around this behavior.

Question

Is this the intended behavior, or should verbosity be propagated so that -v actually reveals the skipped leading characters?

Happy to work on a fix if this is unintended.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions