File: test_pytest_diff_fix.py

package info (click to toggle)
python-inline-snapshot 0.23.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,116 kB
  • sloc: python: 6,888; makefile: 34; sh: 28
file content (70 lines) | stat: -rw-r--r-- 1,807 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import pytest
from executing import is_pytest_compatible

from inline_snapshot import snapshot
from inline_snapshot.testing._example import Example


@pytest.mark.skipif(
    not is_pytest_compatible(),
    reason="pytest assert rewriting and report can not be used at the same time",
)
def test_pytest_diff_fix():

    Example(
        """\
from inline_snapshot import snapshot,Is


def test_dict_report():
    usd = snapshot({"name": "US Dollar", "code": "USD", "symbol": "$"})
    usd2 = Is([1,2])

    price = {
        "amount": 1,
        "currency": {
            "code": "USD",
            "name": "US Dollar",
            "symbol": "$",
        },
        "b":[1,2]
    }

    assert price == snapshot({
        "amount": 2,
        "currency": usd,
        "b":usd2
    })
"""
    ).run_pytest(
        ["--inline-snapshot=report", "-vv"],
        error=snapshot(
            """\
>       assert price == snapshot({
E       AssertionError: assert {'amount': 1, 'currency': {'code': 'USD', 'name': 'US Dollar', 'symbol': '$'}, 'b': [1, 2]} == {'amount': 2, 'currency': {'name': 'US Dollar', 'code': 'USD', 'symbol': '$'}, 'b': [1, 2]}
E         \n\
E         Common items:
E         {'b': [1, 2], 'currency': {'code': 'USD', 'name': 'US Dollar', 'symbol': '$'}}
E         Differing items:
E         {'amount': 1} != {'amount': 2}
E         \n\
E         Full diff:
E           {
E         -     'amount': 2,
E         ?               ^
E         +     'amount': 1,
E         ?               ^
E               'b': [
E                   1,
E                   2,
E               ],
E               'currency': {
E                   'code': 'USD',
E                   'name': 'US Dollar',
E                   'symbol': '$',
E               },
E           }
"""
        ),
        returncode=1,
    )