File: test_snapshot_option_diff_mode.py

package info (click to toggle)
python-syrupy 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,396 kB
  • sloc: python: 5,982; makefile: 3
file content (49 lines) | stat: -rw-r--r-- 1,308 bytes parent folder | download | duplicates (2)
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
import pytest


@pytest.fixture
def testfile(testdir) -> pytest.Testdir:
    testdir.makepyfile(
        test_file=(
            """
            def test_case(snapshot):
                assert snapshot == "some-value"
            """
        ),
    )
    return testdir


def test_diff_mode_disabled_does_not_print_diff(
    testfile,
):
    # Generate initial snapshot
    result = testfile.runpytest("-v", "--snapshot-update")
    result.stdout.re_match_lines((r"1 snapshot generated\.",))
    assert result.ret == 0

    # Modify snapshot to generate diff
    testfile.makepyfile(
        test_file=(
            """
            def test_case(snapshot):
                assert snapshot == "some-other-value"
            """
        ),
    )

    # With diff we expect to see "some-other-value"
    result = testfile.runpytest("-v", "--snapshot-diff-mode=detailed")
    result.stdout.re_match_lines(
        (
            r".*- 'some-value'",
            r".*\+ 'some-other-value'",
        )
    )
    assert result.ret == 1

    # Without diff we do not expect to see "some-other-value"
    result = testfile.runpytest("-v", "--snapshot-diff-mode=disabled")
    result.stdout.no_re_match_line(r".*- 'some-value'")
    result.stdout.no_re_match_line(r".*\+ 'some-other-value'")
    assert result.ret == 1