|
| 1 | +import pytest |
| 2 | + |
| 3 | + |
| 4 | +@pytest.fixture(scope="module") |
| 5 | +def marker_test_file(): |
| 6 | + yield ( |
| 7 | + """ |
| 8 | + import pytest |
| 9 | +
|
| 10 | + @pytest.mark.my3 |
| 11 | + def test_a(): |
| 12 | + pass |
| 13 | +
|
| 14 | + @pytest.mark.my1 |
| 15 | + def test_b(): |
| 16 | + pass |
| 17 | +
|
| 18 | + @pytest.mark.my2 |
| 19 | + def test_c(): |
| 20 | + pass |
| 21 | + """ |
| 22 | + ) |
| 23 | + |
| 24 | + |
| 25 | +@pytest.fixture |
| 26 | +def marker_test(test_path, marker_test_file): |
| 27 | + test_path.makepyfile(test_marker=marker_test_file) |
| 28 | + yield test_path |
| 29 | + |
| 30 | + |
| 31 | +def test_no_ordering(marker_test_file, item_names_for): |
| 32 | + assert item_names_for(marker_test_file) == ["test_a", "test_b", "test_c"] |
| 33 | + |
| 34 | + |
| 35 | +def test_order_with_marker_prefix(marker_test): |
| 36 | + result = marker_test.runpytest("-v", "--order-marker-prefix=my") |
| 37 | + result.assert_outcomes(passed=3, skipped=0) |
| 38 | + result.stdout.fnmatch_lines( |
| 39 | + [ |
| 40 | + "test_marker.py::test_b PASSED", |
| 41 | + "test_marker.py::test_c PASSED", |
| 42 | + "test_marker.py::test_a PASSED", |
| 43 | + ] |
| 44 | + ) |
| 45 | + |
| 46 | + |
| 47 | +def test_order_with_marker_prefix_filtered(marker_test): |
| 48 | + result = marker_test.runpytest("-v", "--order-marker-prefix=my", "-m", "my2 or my3") |
| 49 | + result.assert_outcomes(passed=2, skipped=0) |
| 50 | + result.stdout.fnmatch_lines( |
| 51 | + [ |
| 52 | + "test_marker.py::test_c PASSED", |
| 53 | + "test_marker.py::test_a PASSED", |
| 54 | + ] |
| 55 | + ) |
| 56 | + |
| 57 | + |
| 58 | +def test_no_ordering_with_incorrect_marker_prefix(marker_test): |
| 59 | + result = marker_test.runpytest("-v", "--order-marker-prefix=mi") |
| 60 | + result.assert_outcomes(passed=3, skipped=0) |
| 61 | + result.stdout.fnmatch_lines( |
| 62 | + [ |
| 63 | + "test_marker.py::test_a PASSED", |
| 64 | + "test_marker.py::test_b PASSED", |
| 65 | + "test_marker.py::test_c PASSED", |
| 66 | + ] |
| 67 | + ) |
| 68 | + |
| 69 | + |
| 70 | +def test_no_ordering_with_shorter_marker_prefix(marker_test): |
| 71 | + result = marker_test.runpytest("-v", "--order-marker-prefix=m") |
| 72 | + result.assert_outcomes(passed=3, skipped=0) |
| 73 | + result.stdout.fnmatch_lines( |
| 74 | + [ |
| 75 | + "test_marker.py::test_a PASSED", |
| 76 | + "test_marker.py::test_b PASSED", |
| 77 | + "test_marker.py::test_c PASSED", |
| 78 | + ] |
| 79 | + ) |
| 80 | + |
| 81 | + |
| 82 | +def test_marker_prefix_does_not_interfere_with_order_marks(test_path): |
| 83 | + test_path.makepyfile( |
| 84 | + test_marker=( |
| 85 | + """ |
| 86 | + import pytest |
| 87 | +
|
| 88 | + @pytest.mark.order(3) |
| 89 | + def test_a(): |
| 90 | + pass |
| 91 | +
|
| 92 | + @pytest.mark.order(1) |
| 93 | + def test_b(): |
| 94 | + pass |
| 95 | +
|
| 96 | + @pytest.mark.order(2) |
| 97 | + def test_c(): |
| 98 | + pass |
| 99 | + """ |
| 100 | + ) |
| 101 | + ) |
| 102 | + result = test_path.runpytest("-v", "--order-marker-prefix=m") |
| 103 | + result.assert_outcomes(passed=3, skipped=0) |
| 104 | + result.stdout.fnmatch_lines( |
| 105 | + [ |
| 106 | + "test_marker.py::test_b PASSED", |
| 107 | + "test_marker.py::test_c PASSED", |
| 108 | + "test_marker.py::test_a PASSED", |
| 109 | + ] |
| 110 | + ) |
| 111 | + |
| 112 | + |
| 113 | +def test_mix_marker_prefix_with_order_marks(test_path): |
| 114 | + test_path.makepyfile( |
| 115 | + test_marker=( |
| 116 | + """ |
| 117 | + import pytest |
| 118 | +
|
| 119 | + @pytest.mark.order(3) |
| 120 | + def test_a(): |
| 121 | + pass |
| 122 | +
|
| 123 | + @pytest.mark.my1 |
| 124 | + def test_b(): |
| 125 | + pass |
| 126 | +
|
| 127 | + @pytest.mark.my2 |
| 128 | + def test_c(): |
| 129 | + pass |
| 130 | + """ |
| 131 | + ) |
| 132 | + ) |
| 133 | + result = test_path.runpytest("-v", "--order-marker-prefix=my") |
| 134 | + result.assert_outcomes(passed=3, skipped=0) |
| 135 | + result.stdout.fnmatch_lines( |
| 136 | + [ |
| 137 | + "test_marker.py::test_b PASSED", |
| 138 | + "test_marker.py::test_c PASSED", |
| 139 | + "test_marker.py::test_a PASSED", |
| 140 | + ] |
| 141 | + ) |
0 commit comments