hjwp / hjwp/pytest-icdiff

Locating a diff from context might be hard

Open
#42 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
329
Forks
16
PR merge metrics
No merged PRs in 30d

Description

pytest-icdiff is awesome.

## Problem

When testing small dicts it returns the full diff, but on big structures it only returns those parts that differ (see #25). Sometimes (in the case of big, nested dicts with similar parts in them) this makes it hard to locate where those diffs happen though. The context might not be enough to find where the difference is.

### Example

#### The test

```python

import copy

def big_structure(n):
"""Create a deeply nested tree of dicts"""
if n == 0:
return dict()
return {
"a": big_structure(n-1),
"b": big_structure(n-1),
}

def test_icdiffs():
expected_structure = big_structure(6)

real_structure = copy.deepcopy(expected_structure)
real_structure["a"]["b"]["b"]["a"]["a"]["b"] = "BOOM!" # create a difference

assert expected_structure == real_structure
```

#### The result

![Screenshot_2023-07-20_14:27:19](https://github.com/hjwp/pytest-icdiff/assets/3586246/e3a9efa8-71af-4cf5-a138-796aee2e1d78)

As you can see it is very hard (if even possible) to retrieve the path of the differing field (`("a", "b", "b", "a", "a", "b")`).
This path is often is important to know to fix the error though

## Suggested Solution

if pytest is called with -vvv (oder another appropriate level of verbosity) then the context could be disabled, showing the full diff.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.