|
| 1 | +from pathlib import Path |
| 2 | + |
1 | 3 | import pytest
|
| 4 | +from _pytest.cacheprovider import Cache |
2 | 5 | from _pytest.monkeypatch import MonkeyPatch
|
3 | 6 | from _pytest.pytester import Pytester
|
| 7 | +from _pytest.stepwise import STEPWISE_CACHE_DIR |
4 | 8 |
|
5 | 9 |
|
6 | 10 | @pytest.fixture
|
@@ -278,3 +282,76 @@ def test_three():
|
278 | 282 | def test_sw_skip_help(pytester: Pytester) -> None:
|
279 | 283 | result = pytester.runpytest("-h")
|
280 | 284 | result.stdout.fnmatch_lines("*Implicitly enables --stepwise.")
|
| 285 | + |
| 286 | + |
| 287 | +def test_stepwise_xdist_dont_store_lastfailed(pytester: Pytester) -> None: |
| 288 | + pytester.makefile( |
| 289 | + ext=".ini", |
| 290 | + pytest=f"[pytest]\ncache_dir = {pytester.path}\n", |
| 291 | + ) |
| 292 | + |
| 293 | + pytester.makepyfile( |
| 294 | + conftest=""" |
| 295 | +import pytest |
| 296 | +
|
| 297 | +@pytest.hookimpl(tryfirst=True) |
| 298 | +def pytest_configure(config) -> None: |
| 299 | + config.workerinput = True |
| 300 | +""" |
| 301 | + ) |
| 302 | + pytester.makepyfile( |
| 303 | + test_one=""" |
| 304 | +def test_one(): |
| 305 | + assert False |
| 306 | +""" |
| 307 | + ) |
| 308 | + result = pytester.runpytest("--stepwise") |
| 309 | + assert result.ret == pytest.ExitCode.INTERRUPTED |
| 310 | + |
| 311 | + stepwise_cache_file = ( |
| 312 | + pytester.path / Cache._CACHE_PREFIX_VALUES / STEPWISE_CACHE_DIR |
| 313 | + ) |
| 314 | + assert not Path(stepwise_cache_file).exists() |
| 315 | + |
| 316 | + |
| 317 | +def test_disabled_stepwise_xdist_dont_clear_cache(pytester: Pytester) -> None: |
| 318 | + pytester.makefile( |
| 319 | + ext=".ini", |
| 320 | + pytest=f"[pytest]\ncache_dir = {pytester.path}\n", |
| 321 | + ) |
| 322 | + |
| 323 | + stepwise_cache_file = ( |
| 324 | + pytester.path / Cache._CACHE_PREFIX_VALUES / STEPWISE_CACHE_DIR |
| 325 | + ) |
| 326 | + stepwise_cache_dir = stepwise_cache_file.parent |
| 327 | + stepwise_cache_dir.mkdir(exist_ok=True, parents=True) |
| 328 | + |
| 329 | + stepwise_cache_file_relative = f"{Cache._CACHE_PREFIX_VALUES}/{STEPWISE_CACHE_DIR}" |
| 330 | + |
| 331 | + expected_value = '"test_one.py::test_one"' |
| 332 | + content = {f"{stepwise_cache_file_relative}": expected_value} |
| 333 | + |
| 334 | + pytester.makefile(ext="", **content) |
| 335 | + |
| 336 | + pytester.makepyfile( |
| 337 | + conftest=""" |
| 338 | +import pytest |
| 339 | +
|
| 340 | +@pytest.hookimpl(tryfirst=True) |
| 341 | +def pytest_configure(config) -> None: |
| 342 | + config.workerinput = True |
| 343 | +""" |
| 344 | + ) |
| 345 | + pytester.makepyfile( |
| 346 | + test_one=""" |
| 347 | +def test_one(): |
| 348 | + assert True |
| 349 | +""" |
| 350 | + ) |
| 351 | + result = pytester.runpytest() |
| 352 | + assert result.ret == 0 |
| 353 | + |
| 354 | + assert Path(stepwise_cache_file).exists() |
| 355 | + with stepwise_cache_file.open() as file_handle: |
| 356 | + observed_value = file_handle.readlines() |
| 357 | + assert [expected_value] == observed_value |
0 commit comments