diff --git a/changelog/6290.bugfix.rst b/changelog/6290.bugfix.rst new file mode 100644 index 00000000000..1525e23fe94 --- /dev/null +++ b/changelog/6290.bugfix.rst @@ -0,0 +1 @@ +The supporting files in the ``.pytest_cache`` directory will be properly restored after running ``--cache-clear``. diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py index 6e53545d630..9fbe97d9238 100755 --- a/src/_pytest/cacheprovider.py +++ b/src/_pytest/cacheprovider.py @@ -49,7 +49,6 @@ def for_config(cls, config): cachedir = cls.cache_dir_from_config(config) if config.getoption("cacheclear") and cachedir.exists(): rm_rf(cachedir) - cachedir.mkdir() return cls(cachedir, config) @staticmethod diff --git a/testing/test_cacheprovider.py b/testing/test_cacheprovider.py index 0e1194b02a0..f0b279abf31 100644 --- a/testing/test_cacheprovider.py +++ b/testing/test_cacheprovider.py @@ -270,6 +270,7 @@ def test_3(): assert 0 ) result = testdir.runpytest(str(p), "--lf", "--cache-clear") result.stdout.fnmatch_lines(["*1 failed*2 passed*"]) + assert testdir.tmpdir.join(".pytest_cache", "README.md").isfile() # Run this again to make sure clear-cache is robust if os.path.isdir(".pytest_cache"):