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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
"""Simple dependencies between tests.
"""
import pytest
def test_no_skip(ctestdir):
"""One test is skipped, but no other test depends on it,
so all other tests pass.
"""
ctestdir.makepyfile("""
import pytest
@pytest.mark.dependency()
def test_a():
pytest.skip("explicit skip")
@pytest.mark.dependency()
def test_b():
pass
@pytest.mark.dependency(depends=["test_b"])
def test_c():
pass
@pytest.mark.dependency(depends=["test_c"])
def test_d():
pass
""")
result = ctestdir.runpytest("--verbose")
result.assert_outcomes(passed=3, skipped=1, failed=0)
result.stdout.re_match_lines(r"""
.*::test_a SKIPPED(?:\s+\(.*\))?
.*::test_b PASSED
.*::test_c PASSED
.*::test_d PASSED
""")
def test_skip_depend(ctestdir):
"""One test is skipped, other dependent tests are skipped as well.
This also includes indirect dependencies.
"""
ctestdir.makepyfile("""
import pytest
@pytest.mark.dependency()
def test_a():
pass
@pytest.mark.dependency()
def test_b():
pytest.skip("explicit skip")
@pytest.mark.dependency(depends=["test_b"])
def test_c():
pass
@pytest.mark.dependency(depends=["test_c"])
def test_d():
pass
""")
result = ctestdir.runpytest("--verbose")
result.assert_outcomes(passed=1, skipped=3, failed=0)
result.stdout.re_match_lines(r"""
.*::test_a PASSED
.*::test_b SKIPPED(?:\s+\(.*\))?
.*::test_c SKIPPED(?:\s+\(.*\))?
.*::test_d SKIPPED(?:\s+\(.*\))?
""")
def test_fail_depend(ctestdir):
"""One test fails, other dependent tests are skipped.
This also includes indirect dependencies.
"""
ctestdir.makepyfile("""
import pytest
@pytest.mark.dependency()
def test_a():
pass
@pytest.mark.dependency()
def test_b():
assert False
@pytest.mark.dependency(depends=["test_b"])
def test_c():
pass
@pytest.mark.dependency(depends=["test_c"])
def test_d():
pass
""")
result = ctestdir.runpytest("--verbose")
result.assert_outcomes(passed=1, skipped=2, failed=1)
result.stdout.re_match_lines(r"""
.*::test_a PASSED
.*::test_b FAILED
.*::test_c SKIPPED(?:\s+\(.*\))?
.*::test_d SKIPPED(?:\s+\(.*\))?
""")
def test_named_fail_depend(ctestdir):
"""Same as test_fail_depend, but using custom test names.
"""
ctestdir.makepyfile("""
import pytest
@pytest.mark.dependency(name="a")
def test_a():
pass
@pytest.mark.dependency(name="b")
def test_b():
assert False
@pytest.mark.dependency(name="c", depends=["b"])
def test_c():
pass
@pytest.mark.dependency(name="d", depends=["c"])
def test_d():
pass
""")
result = ctestdir.runpytest("--verbose")
result.assert_outcomes(passed=1, skipped=2, failed=1)
result.stdout.re_match_lines(r"""
.*::test_a PASSED
.*::test_b FAILED
.*::test_c SKIPPED(?:\s+\(.*\))?
.*::test_d SKIPPED(?:\s+\(.*\))?
""")
def test_explicit_select(ctestdir):
"""Explicitly select only a single test that depends on another one.
Since the other test has not been run at all, the selected test
will be skipped.
"""
ctestdir.makepyfile("""
import pytest
@pytest.mark.dependency()
def test_a():
pass
@pytest.mark.dependency()
def test_b():
pass
@pytest.mark.dependency()
def test_c():
pass
@pytest.mark.dependency(depends=["test_c"])
def test_d():
pass
""")
result = ctestdir.runpytest("--verbose", "test_explicit_select.py::test_d")
result.assert_outcomes(passed=0, skipped=1, failed=0)
result.stdout.re_match_lines(r"""
.*::test_d SKIPPED(?:\s+\(.*\))?
""")
def test_depend_unknown(ctestdir):
"""Depend on an unknown test that is not even defined in the test set.
Note that is not an error to depend on an undefined test, but the
dependent test will be skipped since the non-existent dependency
has not been run successfully.
"""
ctestdir.makepyfile("""
import pytest
@pytest.mark.dependency()
def test_a():
pass
@pytest.mark.dependency()
def test_b():
pass
@pytest.mark.dependency()
def test_c():
pass
@pytest.mark.dependency(depends=["test_x"])
def test_d():
pass
""")
result = ctestdir.runpytest("--verbose")
result.assert_outcomes(passed=3, skipped=1, failed=0)
result.stdout.re_match_lines(r"""
.*::test_a PASSED
.*::test_b PASSED
.*::test_c PASSED
.*::test_d SKIPPED(?:\s+\(.*\))?
""")
|