diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py index eb0fcc06f..ff2d1e285 100755 --- a/src/_pytest/cacheprovider.py +++ b/src/_pytest/cacheprovider.py @@ -103,6 +103,22 @@ class Cache(object): with f: self.trace("cache-write %s: %r" % (key, value)) json.dump(value, f, indent=2, sort_keys=True) + self._ensure_readme() + + def _ensure_readme(self): + content_readme = '''# pytest cache directory # + +This directory contains data from the pytest's cache plugin, \ +which provides the `--lf` and `--ff` options, as well as the `cache` fixture. + +**Do not** commit this to version control. + +See [the docs](https://docs.pytest.org/en/latest/cache.html) for more information. + ''' + if self._cachedir.check(dir=True): + readme_path = self._cachedir.join("README.md") + if not readme_path.check(file=True): + readme_path.write(content_readme) class LFPlugin(object):