Skip to content

(🎁) color the diff of strings #13175

@KotlinIsland

Description

@KotlinIsland
def test_list():
    assert [1, 2, 3] == [1, 4, 3]
def test_str():
    assert "asdf" == "asgf"

Warning

it is CRITICAL that pygments is installed, otherwise the diff won't be colored at all
this is a secret undocumented feature, see: #13174

> uv init
> uv add pytest pygments
...
> uv run pytest -vv
FAILED test_test.py::test_list - assert [1, 2, 3] == [1, 4, 3]

  At index 1 diff: 2 != 4

  Full diff:
    [
        1,
  -     4,
  ?     ^
  +     2,
  ?     ^
        3,
    ]
FAILED test_test.py::test_str - AssertionError: assert 'asdf' == 'asgf'

  - asgf
  ?   ^
  + asdf
  ?   ^

Image

here we can observe that no coloring has been applied to the string diff

  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
    > uv tree
    uv tree
    Resolved 7 packages in 4ms
    test v1
    ├── pygments v2.19.1
    └── pytest v8.3.4
        ├── colorama v0.4.6
        ├── iniconfig v2.0.0
        ├── packaging v24.2
        └── pluggy v1.5.0
    
  • pytest and operating system versions
    windows 10
  • minimal example if possible

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