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
|
from textwrap import dedent
import pytest
@pytest.fixture
def fixture_path(test_path):
test_a_contents = dedent(
"""
import pytest
@pytest.mark.order(4)
def test_four(): pass
@pytest.mark.order(3)
def test_three(): pass
"""
)
test_b_contents = dedent(
"""
import pytest
@pytest.mark.order(2)
def test_two(): pass
@pytest.mark.order(1)
def test_one(): pass
"""
)
for i in range(3):
sub_path = f"feature{i}"
test_path.mkpydir(sub_path)
path = test_path.tmpdir.join(sub_path, "test_a.py")
path.write(test_a_contents)
path = test_path.tmpdir.join(sub_path, "test_b.py")
path.write(test_b_contents)
yield test_path
def test_session_scope(fixture_path):
result = fixture_path.runpytest("-v")
result.assert_outcomes(passed=12, failed=0)
result.stdout.fnmatch_lines(
[
"feature0/test_b.py::test_one PASSED",
"feature1/test_b.py::test_one PASSED",
"feature2/test_b.py::test_one PASSED",
"feature0/test_b.py::test_two PASSED",
"feature1/test_b.py::test_two PASSED",
"feature2/test_b.py::test_two PASSED",
"feature0/test_a.py::test_three PASSED",
"feature1/test_a.py::test_three PASSED",
"feature2/test_a.py::test_three PASSED",
"feature0/test_a.py::test_four PASSED",
"feature1/test_a.py::test_four PASSED",
"feature2/test_a.py::test_four PASSED",
]
)
def test_dir_level0(fixture_path, capsys):
"""Same as session scope."""
result = fixture_path.runpytest("-v", "--order-scope-level=0")
result.assert_outcomes(passed=12, failed=0)
result.stdout.fnmatch_lines(
[
"feature0/test_b.py::test_one PASSED",
"feature1/test_b.py::test_one PASSED",
"feature2/test_b.py::test_one PASSED",
"feature0/test_b.py::test_two PASSED",
"feature1/test_b.py::test_two PASSED",
"feature2/test_b.py::test_two PASSED",
"feature0/test_a.py::test_three PASSED",
"feature1/test_a.py::test_three PASSED",
"feature2/test_a.py::test_three PASSED",
"feature0/test_a.py::test_four PASSED",
"feature1/test_a.py::test_four PASSED",
"feature2/test_a.py::test_four PASSED",
]
)
def test_dir_level1(fixture_path, capsys):
"""Orders per feature path."""
result = fixture_path.runpytest("-v", "--order-scope-level=1")
result.assert_outcomes(passed=12, failed=0)
result.stdout.fnmatch_lines(
[
"feature0/test_b.py::test_one PASSED",
"feature0/test_b.py::test_two PASSED",
"feature0/test_a.py::test_three PASSED",
"feature0/test_a.py::test_four PASSED",
"feature1/test_b.py::test_one PASSED",
"feature1/test_b.py::test_two PASSED",
"feature1/test_a.py::test_three PASSED",
"feature1/test_a.py::test_four PASSED",
"feature2/test_b.py::test_one PASSED",
"feature2/test_b.py::test_two PASSED",
"feature2/test_a.py::test_three PASSED",
"feature2/test_a.py::test_four PASSED",
]
)
def test_dir_level2(fixture_path, capsys):
"""Same as module scope."""
result = fixture_path.runpytest("-v", "--order-scope-level=2")
result.assert_outcomes(passed=12, failed=0)
result.stdout.fnmatch_lines(
[
"feature0/test_a.py::test_three PASSED",
"feature0/test_a.py::test_four PASSED",
"feature0/test_b.py::test_one PASSED",
"feature0/test_b.py::test_two PASSED",
"feature1/test_a.py::test_three PASSED",
"feature1/test_a.py::test_four PASSED",
"feature1/test_b.py::test_one PASSED",
"feature1/test_b.py::test_two PASSED",
"feature2/test_a.py::test_three PASSED",
"feature2/test_a.py::test_four PASSED",
"feature2/test_b.py::test_one PASSED",
"feature2/test_b.py::test_two PASSED",
]
)
@pytest.mark.skipif(
pytest.__version__.startswith("3.7."),
reason="Warning does not appear in output in pytest < 3.8",
)
def test_invalid_scope(fixture_path):
result = fixture_path.runpytest(
"-v", "--order-scope=module", "--order-scope-level=1"
)
result.assert_outcomes(passed=12, failed=0)
result.stdout.fnmatch_lines(
[
"*UserWarning: order-scope-level cannot be used "
"together with --order-scope=module*"
]
)
|