Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
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.
Debug
Known issues
gotchaSubtle type differences (e.g., integer 5 vs. float 5.0) might not always be highlighted as distinct changes in the diff output. The underlying `icdiff` library might choose to represent them similarly to avoid 'false-positive' colorization, potentially masking minor distinctions that could be relevant in some contexts.fixManually inspect assertions for edge cases involving type-sensitive comparisons or use explicit type checks in your tests if such distinctions are critical.
affects: All versions
gotchaThe enhanced diffing provided by `pytest-icdiff` is primarily designed for and most effective with `assert ==` (equality comparisons). Other types of assertions, such as `assert 'substring' in my_string`, `assert obj is None`, or custom assertion helpers, will revert to `pytest`'s default output format and will not benefit from the `icdiff` formatting.fixBe aware that not all assertion failures will display `icdiff`'s enhanced output. Focus on `assert ==` for complex object comparisons to leverage the plugin fully.
affects: All versions
gotchaWhile `pytest-icdiff` aims for broad compatibility, `pytest` itself undergoes frequent updates, including major version bumps with breaking changes (e.g., dropping Python version support or internal API modifications). Although `pytest-icdiff` currently supports Python >=3.7 and lists a general `pytest` dependency, ensure your specific `pytest` version is compatible to avoid unexpected behavior or conflicts.fixRegularly check the `pytest-icdiff` GitHub repository for updates on `pytest` compatibility. When upgrading `pytest`, test your suite thoroughly to catch any unforeseen interactions.
affects: All `pytest-icdiff` versions in conjunction with new/old `pytest` versions.
Upgrade
Version history
0.9latest on PyPI · released Dec 5, 2023
Audit
Dependencies
pytestrequiredCore testing framework that this plugin extends.
icdiffrequiredProvides the side-by-side diffing logic used for enhanced output.
pprintppoptionalUsed for pretty-printing data structures before diffing, contributing to improved readability.