File: test_xfail.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 (56 lines) | stat: -rw-r--r-- 1,628 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
def test_no_failure_printed_if_all_failures_xfailed(testdir, plugin_args):
    testdir.makepyfile(
        test_file=(
            """
        import pytest

        @pytest.mark.xfail(reason="Failure expected.")
        def test_a(snapshot):
            assert snapshot == 'does-not-exist'
        """
        )
    )
    result = testdir.runpytest("-v", *plugin_args)
    result.stdout.no_re_match_line(r".*snapshot failed*")
    assert result.ret == 0


def test_failures_printed_if_only_some_failures_xfailed(
    testdir, plugin_args_fails_xdist
):
    testdir.makepyfile(
        test_file=(
            """
        import pytest

        @pytest.mark.xfail(reason="Failure expected.")
        def test_a(snapshot):
            assert snapshot == 'does-not-exist'

        def test_b(snapshot):
            assert snapshot == 'other'
        """
        )
    )
    result = testdir.runpytest("-v", *plugin_args_fails_xdist)
    result.stdout.re_match_lines((r".*1 snapshot failed*",))
    result.stdout.re_match_lines((r".*1 snapshot xfailed*",))
    assert result.ret == 1


def test_failure_printed_if_xfail_does_not_run(testdir, plugin_args_fails_xdist):
    testdir.makepyfile(
        test_file=(
            """
        import pytest

        @pytest.mark.xfail(False, reason="Failure expected.")
        def test_a(snapshot):
            assert snapshot == 'does-not-exist'
        """
        )
    )
    result = testdir.runpytest("-v", *plugin_args_fails_xdist)
    result.stdout.re_match_lines((r".*1 snapshot failed*",))
    result.stdout.no_re_match_line(r".*1 snapshot xfailed*")
    assert result.ret == 1