|
1 | 1 | # -*- coding: utf-8 -*-
|
| 2 | +import sys |
| 3 | + |
2 | 4 | import pytest
|
3 | 5 |
|
4 | 6 |
|
@@ -166,3 +168,57 @@ def test_stop_on_collection_errors(broken_testdir, broken_first):
|
166 | 168 | files.reverse()
|
167 | 169 | result = broken_testdir.runpytest("-v", "--strict-markers", "--stepwise", *files)
|
168 | 170 | result.stdout.fnmatch_lines("*errors during collection*")
|
| 171 | + |
| 172 | + |
| 173 | +def test_xfail_handling(testdir): |
| 174 | + """Ensure normal xfail is ignored, and strict xfail interrupts the session in sw mode |
| 175 | +
|
| 176 | + (#5547) |
| 177 | + """ |
| 178 | + contents = """ |
| 179 | + import pytest |
| 180 | + def test_a(): pass |
| 181 | +
|
| 182 | + @pytest.mark.xfail(strict={strict}) |
| 183 | + def test_b(): assert {assert_value} |
| 184 | +
|
| 185 | + def test_c(): pass |
| 186 | + def test_d(): pass |
| 187 | + """ |
| 188 | + testdir.makepyfile(contents.format(assert_value="0", strict="False")) |
| 189 | + result = testdir.runpytest("--sw", "-v") |
| 190 | + result.stdout.fnmatch_lines( |
| 191 | + [ |
| 192 | + "*::test_a PASSED *", |
| 193 | + "*::test_b XFAIL *", |
| 194 | + "*::test_c PASSED *", |
| 195 | + "*::test_d PASSED *", |
| 196 | + "* 3 passed, 1 xfailed in *", |
| 197 | + ] |
| 198 | + ) |
| 199 | + |
| 200 | + testdir.makepyfile(contents.format(assert_value="1", strict="True")) |
| 201 | + result = testdir.runpytest("--sw", "-v") |
| 202 | + result.stdout.fnmatch_lines( |
| 203 | + [ |
| 204 | + "*::test_a PASSED *", |
| 205 | + "*::test_b FAILED *", |
| 206 | + "* Interrupted*", |
| 207 | + "* 1 failed, 1 passed in *", |
| 208 | + ] |
| 209 | + ) |
| 210 | + |
| 211 | + # because we are writing to the same file, mtime might not be affected enough to |
| 212 | + # invalidate the cache, making this next run flaky |
| 213 | + if not sys.dont_write_bytecode: |
| 214 | + testdir.tmpdir.join("__pycache__").remove() |
| 215 | + testdir.makepyfile(contents.format(assert_value="0", strict="True")) |
| 216 | + result = testdir.runpytest("--sw", "-v") |
| 217 | + result.stdout.fnmatch_lines( |
| 218 | + [ |
| 219 | + "*::test_b XFAIL *", |
| 220 | + "*::test_c PASSED *", |
| 221 | + "*::test_d PASSED *", |
| 222 | + "* 2 passed, 1 deselected, 1 xfailed in *", |
| 223 | + ] |
| 224 | + ) |
0 commit comments