{"id":1666,"library":"pytest-icdiff","title":"pytest-icdiff","description":"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.","status":"active","version":"0.9","language":"en","source_language":"en","source_url":"https://github.com/hjwp/pytest-icdiff","tags":["pytest","testing","diff","assertion","developer-tools","quality-of-life"],"install":[{"cmd":"pip install pytest-icdiff","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Core testing framework that this plugin extends.","package":"pytest","optional":false},{"reason":"Provides the side-by-side diffing logic used for enhanced output.","package":"icdiff","optional":false},{"reason":"Used for pretty-printing data structures before diffing, contributing to improved readability.","package":"pprintpp","optional":true}],"imports":[],"quickstart":{"code":"import pytest\n\n# test_example.py\ndef test_dictionary_comparison_failure():\n    expected_data = {\"name\": \"Alice\", \"age\": 30, \"city\": \"New York\"}\n    actual_data = {\"name\": \"Bob\", \"age\": 31, \"city\": \"London\", \"occupation\": \"Engineer\"}\n    assert expected_data == actual_data\n\ndef test_list_comparison_failure():\n    expected_list = [1, 2, 3, \"a\", 5]\n    actual_list = [1, 2, 4, \"b\", 5]\n    assert expected_list == actual_list\n\n# To run this example, save it as a .py file (e.g., test_example.py)\n# and execute `pytest -q test_example.py` in your terminal.\n# pytest-icdiff will automatically enhance the output for failed assertions.","lang":"python","description":"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."},"warnings":[{"fix":"Manually inspect assertions for edge cases involving type-sensitive comparisons or use explicit type checks in your tests if such distinctions are critical.","message":"Subtle 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware that not all assertion failures will display `icdiff`'s enhanced output. Focus on `assert ==` for complex object comparisons to leverage the plugin fully.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Regularly check the `pytest-icdiff` GitHub repository for updates on `pytest` compatibility. When upgrading `pytest`, test your suite thoroughly to catch any unforeseen interactions.","message":"While `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.","severity":"gotcha","affected_versions":"All `pytest-icdiff` versions in conjunction with new/old `pytest` versions."}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}