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

Function test_cache_error

testing/test_stepwise.py:515–545  ·  view source on GitHub ↗
(pytester: Pytester)

Source from the content-addressed store, hash-verified

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…