Pytest DeepAssert Plugin

0.3.0 · active · verified Thu Apr 16

pytest-deepassert is a pytest plugin (current version 0.3.0) designed to enhance assertion reporting, particularly for complex data structures. Built upon the powerful `deepdiff` library, it provides clear, detailed difference reports, highlighting exact changes in nested objects like dictionaries, lists, and custom types. This significantly helps developers quickly identify discrepancies in test failures, offering focused output that pinpoints specific field names, values, and array indices. It has a non-fixed release cadence, with updates typically occurring a few times a year.

Common errors

Warnings

Install

Imports

Quickstart

Create a test file (e.g., `test_example.py`) with a standard `assert` statement comparing complex data structures. Run `pytest` with the `--deepassert` flag to activate the plugin's enhanced reporting. The `-vv` flag increases verbosity to show more details, including the deep diff.

# test_example.py
def test_complex_data_comparison():
    actual_data = {
        "id": 1,
        "name": "Alice",
        "details": {"age": 30, "city": "New York", "preferences": ["email", "sms"]}
    }
    expected_data = {
        "id": 1,
        "name": "Bob", # Name changed
        "details": {"age": 31, "city": "London", "preferences": ["email"]}
    }
    assert actual_data == expected_data

# To run the test and see detailed diffs:
# pytest test_example.py --deepassert -vv

view raw JSON →