From 972cd74cf0b72c9c4de7ff35512998b708cb7967 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 30 Nov 2019 12:11:29 -0300 Subject: [PATCH] Ensure cache supporting files still exist after --cache-clear Fix #6290 --- changelog/6290.bugfix.rst | 1 + src/_pytest/cacheprovider.py | 1 - testing/test_cacheprovider.py | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 changelog/6290.bugfix.rst 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"):