File: test_marker_prefix.py

package info (click to toggle)
pytest-order 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 600 kB
  • sloc: python: 3,483; makefile: 159; sh: 13
file content (163 lines) | stat: -rw-r--r-- 4,230 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import pytest


@pytest.fixture(scope="module")
def marker_test_file():
    yield (
        """
        import pytest

        @pytest.mark.my3
        def test_a():
            pass

        @pytest.mark.my1
        def test_b():
            pass

        @pytest.mark.my2
        def test_c():
            pass
        """
    )


@pytest.fixture(scope="module")
def conftest_file():
    yield (
        """
        def pytest_configure(config):
            config.addinivalue_line("markers", "my1: used in marker prefix test")
            config.addinivalue_line("markers", "my2: used in marker prefix test")
            config.addinivalue_line("markers", "my3: used in marker prefix test")
        """
    )


@pytest.fixture
def marker_test(test_path, marker_test_file, conftest_file):
    test_path.makepyfile(conftest=conftest_file)
    test_path.makepyfile(test_marker=marker_test_file)
    yield test_path


def test_no_ordering(marker_test):
    result = marker_test.runpytest("-v")
    result.assert_outcomes(passed=3, skipped=0)
    result.stdout.fnmatch_lines(
        [
            "test_marker.py::test_a PASSED",
            "test_marker.py::test_b PASSED",
            "test_marker.py::test_c PASSED",
        ]
    )


def test_order_with_marker_prefix(marker_test):
    result = marker_test.runpytest("-v", "--order-marker-prefix=my")
    result.assert_outcomes(passed=3, skipped=0)
    result.stdout.fnmatch_lines(
        [
            "test_marker.py::test_b PASSED",
            "test_marker.py::test_c PASSED",
            "test_marker.py::test_a PASSED",
        ]
    )


def test_order_with_marker_prefix_filtered(marker_test):
    result = marker_test.runpytest("-v", "--order-marker-prefix=my", "-m", "my2 or my3")
    result.assert_outcomes(passed=2, skipped=0)
    result.stdout.fnmatch_lines(
        [
            "test_marker.py::test_c PASSED",
            "test_marker.py::test_a PASSED",
        ]
    )


def test_no_ordering_with_incorrect_marker_prefix(marker_test):
    result = marker_test.runpytest("-v", "--order-marker-prefix=mi")
    result.assert_outcomes(passed=3, skipped=0)
    result.stdout.fnmatch_lines(
        [
            "test_marker.py::test_a PASSED",
            "test_marker.py::test_b PASSED",
            "test_marker.py::test_c PASSED",
        ]
    )


def test_no_ordering_with_shorter_marker_prefix(marker_test):
    result = marker_test.runpytest("-v", "--order-marker-prefix=m")
    result.assert_outcomes(passed=3, skipped=0)
    result.stdout.fnmatch_lines(
        [
            "test_marker.py::test_a PASSED",
            "test_marker.py::test_b PASSED",
            "test_marker.py::test_c PASSED",
        ]
    )


def test_marker_prefix_does_not_interfere_with_order_marks(test_path):
    test_path.makepyfile(
        test_marker=(
            """
            import pytest

            @pytest.mark.order(3)
            def test_a():
                pass

            @pytest.mark.order(1)
            def test_b():
                pass

            @pytest.mark.order(2)
            def test_c():
                pass
            """
        )
    )
    result = test_path.runpytest("-v", "--order-marker-prefix=m")
    result.assert_outcomes(passed=3, skipped=0)
    result.stdout.fnmatch_lines(
        [
            "test_marker.py::test_b PASSED",
            "test_marker.py::test_c PASSED",
            "test_marker.py::test_a PASSED",
        ]
    )


def test_mix_marker_prefix_with_order_marks(test_path, conftest_file):
    test_path.makepyfile(conftest=conftest_file)
    test_path.makepyfile(
        test_marker=(
            """
            import pytest

            @pytest.mark.order(3)
            def test_a():
                pass

            @pytest.mark.my1
            def test_b():
                pass

            @pytest.mark.my2
            def test_c():
                pass
            """
        )
    )
    result = test_path.runpytest("-v", "--order-marker-prefix=my")
    result.assert_outcomes(passed=3, skipped=0)
    result.stdout.fnmatch_lines(
        [
            "test_marker.py::test_b PASSED",
            "test_marker.py::test_c PASSED",
            "test_marker.py::test_a PASSED",
        ]
    )