MCPcopy
hub / github.com/pytest-dev/pytest / test_cache_error

Function test_cache_error

testing/test_stepwise.py:515–545  ·  testing/test_stepwise.py::test_cache_error
(pytester: Pytester)

Source from the content-addressed store, hash-verified

513
514
515def test_cache_error(pytester: Pytester) -> None:
516 pytester.makepyfile(
517 class="st">"""
518 def test_1(): pass
519 class="st">"""
520 )
521 class="cm"># Run stepwise normally to generate the cache information.
522 result = pytester.runpytest(class="st">"--stepwise", class="st">"-v")
523 result.stdout.fnmatch_lines(
524 [
525 class="st">"stepwise: no previously failed tests, not skipping.",
526 class="st">"*::test_1 *PASSED*",
527 class="st">"* 1 passed in *",
528 ]
529 )
530
531 class="cm"># Corrupt the cache.
532 cache_file = pytester.path / fclass="st">".pytest_cache/v/{STEPWISE_CACHE_DIR}"
533 assert cache_file.is_file()
534 cache_file.write_text(json.dumps({class="st">"invalid": True}), encoding=class="st">"UTF-8")
535
536 class="cm"># Check we run as if the cache did not exist, but also show an error message.
537 result = pytester.runpytest(class="st">"--stepwise", class="st">"-v")
538 result.stdout.fnmatch_lines(
539 [
540 class="st">"stepwise: error reading cache, discarding (KeyError: *",
541 class="st">"stepwise: no previously failed tests, not skipping.",
542 class="st">"*::test_1 *PASSED*",
543 class="st">"* 1 passed in *",
544 ]
545 )

Callers

nothing calls this directly

Calls 5

fnmatch_linesMethod · 0.80
write_textMethod · 0.80
dumpsMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected