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.
pip install pytest-deepassertVerified import paths — ran on the pinned version, not inferred.
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.
Always run pytest with `pytest --deepassert` to enable the plugin. Consider adding `--deepassert` to your `pytest.ini` configuration file under `addopts` for automatic inclusion.
Focus on using `pytest-deepassert` for tests involving nested dictionaries, lists of objects, custom classes, or other complex types where standard diffs are hard to parse. For basic types, rely on native pytest reporting.
For assertions outside of `pytest`'s direct test discovery, use the `pytest_deepassert.equal()` function explicitly to get deep comparison reports. For example: `from pytest_deepassert import equal; equal(actual, expected)`.
Ensure you are comparing complex data structures. Run your tests with the `--deepassert` flag: `pytest --deepassert`. If using `pytest.ini`, add `addopts = --deepassert`.
Add `--deepassert` to your pytest command: `pytest your_test_file.py --deepassert`. For continuous use, add `addopts = --deepassert` to your `pytest.ini` configuration file.
Explicitly use the `equal` function provided by the plugin in your helper functions: `from pytest_deepassert import equal; equal(my_actual_value, my_expected_value)`.