File: test_snapshot_similar_names_file_extension.py

package info (click to toggle)
python-syrupy 4.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,368 kB
  • sloc: python: 5,978; makefile: 3
file content (124 lines) | stat: -rw-r--r-- 3,640 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import pytest


@pytest.fixture
def testcases():
    return {
        "a": (
            """
            def test_a(snapshot):
                assert snapshot == b"a"
            """
        ),
        "b": (
            """
            def test_b(snapshot):
                assert snapshot == b"b"
            """
        ),
        "a_suffix": (
            """
            def test_a_suffix(snapshot):
                assert snapshot == b"a_suffix"
            """
        ),
    }


@pytest.fixture
def run_testcases(testdir, testcases):
    pyfile_content = "\n\n".join(testcases.values())
    testdir.makepyfile(
        test_1=pyfile_content, test_2=pyfile_content, test_1_suffix=pyfile_content
    )
    result = testdir.runpytest(
        "-v",
        "--snapshot-update",
        "--snapshot-default-extension",
        "syrupy.extensions.single_file.SingleFileSnapshotExtension",
    )
    result.stdout.re_match_lines((r"9 snapshots generated\.",))
    return testdir, testcases


def test_run_all(run_testcases, plugin_args_fails_xdist):
    testdir, testcases = run_testcases
    result = testdir.runpytest(
        "-v",
        "--snapshot-default-extension",
        "syrupy.extensions.single_file.SingleFileSnapshotExtension",
        *plugin_args_fails_xdist,
    )
    result.stdout.re_match_lines(("9 snapshots passed",))
    assert result.ret == 0


def test_run_single_file(run_testcases, plugin_args_fails_xdist):
    testdir, testcases = run_testcases
    result = testdir.runpytest(
        "-v",
        "--snapshot-default-extension",
        "syrupy.extensions.single_file.SingleFileSnapshotExtension",
        "test_1.py",
        *plugin_args_fails_xdist,
    )
    result.stdout.re_match_lines(("3 snapshots passed",))
    assert result.ret == 0


def test_run_single_test_case_in_file(run_testcases, plugin_args_fails_xdist):
    testdir, testcases = run_testcases
    result = testdir.runpytest(
        "-v",
        "--snapshot-default-extension",
        "syrupy.extensions.single_file.SingleFileSnapshotExtension",
        "test_2.py::test_a",
        *plugin_args_fails_xdist,
    )
    result.stdout.re_match_lines(("1 snapshot passed",))
    assert result.ret == 0


def test_run_all_but_one(run_testcases, plugin_args_fails_xdist):
    testdir, testcases = run_testcases
    result = testdir.runpytest(
        "-v",
        "--snapshot-details",
        "--snapshot-default-extension",
        "syrupy.extensions.single_file.SingleFileSnapshotExtension",
        "test_1.py",
        "test_2.py::test_a",
        *plugin_args_fails_xdist,
    )
    result.stdout.re_match_lines(("4 snapshots passed",))
    assert result.ret == 0


def test_run_both_files_by_node(run_testcases, plugin_args_fails_xdist):
    testdir, testcases = run_testcases
    result = testdir.runpytest(
        "-v",
        "--snapshot-details",
        "--snapshot-default-extension",
        "syrupy.extensions.single_file.SingleFileSnapshotExtension",
        "test_1.py::test_a",
        "test_2.py::test_a",
        *plugin_args_fails_xdist,
    )
    result.stdout.re_match_lines(("2 snapshots passed",))
    assert result.ret == 0


def test_run_both_files_by_node_2(run_testcases, plugin_args_fails_xdist):
    testdir, testcases = run_testcases
    result = testdir.runpytest(
        "-v",
        "--snapshot-details",
        "--snapshot-default-extension",
        "syrupy.extensions.single_file.SingleFileSnapshotExtension",
        "test_1.py::test_b",
        "test_2.py::test_a",
        *plugin_args_fails_xdist,
    )
    result.stdout.re_match_lines(("2 snapshots passed",))
    assert result.ret == 0