.pytest_cache is now automatically ignored by Git
This commit is contained in:
parent
49800ea134
commit
9aa6b0903b
|
@ -0,0 +1 @@
|
|||
``.pytest_cache`` directory is now automatically ignored by Git. Users who would like to contribute a solution for other SCMs please consult/comment on this issue.
|
|
@ -115,15 +115,18 @@ class Cache(object):
|
|||
else:
|
||||
with f:
|
||||
json.dump(value, f, indent=2, sort_keys=True)
|
||||
self._ensure_readme()
|
||||
|
||||
def _ensure_readme(self):
|
||||
self._ensure_supporting_files()
|
||||
|
||||
def _ensure_supporting_files(self):
|
||||
"""Create supporting files in the cache dir that are not really part of the cache."""
|
||||
if self._cachedir.is_dir():
|
||||
readme_path = self._cachedir / "README.md"
|
||||
if not readme_path.is_file():
|
||||
readme_path.write_text(README_CONTENT)
|
||||
|
||||
msg = u"# created by pytest automatically, do not change\n*"
|
||||
self._cachedir.joinpath(".gitignore").write_text(msg, encoding="UTF-8")
|
||||
|
||||
|
||||
class LFPlugin(object):
|
||||
""" Plugin which implements the --lf (run last-failing) option """
|
||||
|
|
|
@ -884,3 +884,14 @@ class TestReadme(object):
|
|||
)
|
||||
testdir.runpytest()
|
||||
assert self.check_readme(testdir) is True
|
||||
|
||||
|
||||
def test_gitignore(testdir):
|
||||
"""Ensure we automatically create .gitignore file in the pytest_cache directory (#3286)."""
|
||||
from _pytest.cacheprovider import Cache
|
||||
|
||||
config = testdir.parseconfig()
|
||||
cache = Cache.for_config(config)
|
||||
cache.set("foo", "bar")
|
||||
msg = "# created by pytest automatically, do not change\n*"
|
||||
assert cache._cachedir.joinpath(".gitignore").read_text(encoding="UTF-8") == msg
|
||||
|
|
Loading…
Reference in New Issue