pytest-icdiff

0.9 · active · verified Thu Apr 09

pytest-icdiff is a plugin for the pytest testing framework that significantly improves the readability of assertion error messages. By leveraging the `icdiff` utility, it provides clear, colorized, side-by-side diffs for failed equality assertions (assert ==), making it easier to pinpoint differences in complex data structures like dictionaries and lists. The current stable version is 0.9, released in December 2023, and it generally maintains an active development status with compatibility for Python 3.7 and newer.

Warnings

Install

Quickstart

After installing `pytest-icdiff`, its functionality is automatically enabled for `pytest` runs. Create a simple test file with failing `assert ==` comparisons to see the enhanced, colorized, side-by-side diffs in action.

import pytest

# test_example.py
def test_dictionary_comparison_failure():
    expected_data = {"name": "Alice", "age": 30, "city": "New York"}
    actual_data = {"name": "Bob", "age": 31, "city": "London", "occupation": "Engineer"}
    assert expected_data == actual_data

def test_list_comparison_failure():
    expected_list = [1, 2, 3, "a", 5]
    actual_list = [1, 2, 4, "b", 5]
    assert expected_list == actual_list

# To run this example, save it as a .py file (e.g., test_example.py)
# and execute `pytest -q test_example.py` in your terminal.
# pytest-icdiff will automatically enhance the output for failed assertions.

view raw JSON →