File: test_pytest_extension.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 (75 lines) | stat: -rw-r--r-- 2,338 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
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
def test_ignores_non_function_nodes(testdir, plugin_args):
    conftest = """
        import pytest

        class CustomItem(pytest.Item):
            def __init__(self, name, **kwargs):
                super().__init__(name, **kwargs)
                self._nodeid += "::CUSTOM"

            def runtest(self):
                pass

        def pytest_collect_file(file_path, parent):
            return CustomItem.from_parent(
                name=file_path.name,
                path=file_path,
                parent=parent
            )
        """
    testcase = """
        def test_example(snapshot):
            assert snapshot == 1
        """
    testdir.makeconftest(conftest)
    testdir.makepyfile(test_file=testcase)
    result = testdir.runpytest("test_file.py", "-v", "--snapshot-update", *plugin_args)
    result.stdout.re_match_lines((r".*test_file.py::CUSTOM.*",))
    assert result.ret == 0


def test_handles_pyargs_non_module_when_both_given(testdir, plugin_args):
    testdir.makeconftest("")
    testcase = """
        def test_example(snapshot):
            assert snapshot == 1
        """
    testdir.makepyfile(test_file=testcase)
    result = testdir.runpytest(
        "-v",
        "test_file.py",
        "--pyargs",
        "test_file",
        "--snapshot-update",
        *plugin_args,
    )
    assert result.ret == 0


def test_does_not_print_empty_snapshot_report(testdir, plugin_args_fails_xdist):
    testdir.makeconftest("")
    testcase_no_snapshots = """
        def test_example(snapshot):
            assert 1
        """
    testcase_yes_snapshots = """
        def test_example(snapshot):
            assert snapshot == 1
        """
    testdir.makepyfile(
        test_file_no=testcase_no_snapshots, test_file_yes=testcase_yes_snapshots
    )

    result = testdir.runpytest(
        "-v", "test_file_no.py", "--snapshot-update", *plugin_args_fails_xdist
    )
    result.stdout.re_match_lines((r".*test_file_no.py.*",))
    assert "snapshot report" not in result.stdout.str()
    assert "test_file_yes" not in result.stdout.str()
    assert result.ret == 0

    result = testdir.runpytest(
        "-v", "test_file_yes.py", "--snapshot-update", *plugin_args_fails_xdist
    )
    result.stdout.re_match_lines((r".*test_file_yes.py.*", r".*snapshot report.*"))
    assert result.ret == 0