Merge pull request #4504 from feuillemorte/4278_add_cachedir_tag
#4278 Added a CACHEDIR.TAG file to the cache directory
This commit is contained in:
commit
0e4e8e00a9
|
@ -0,0 +1 @@
|
||||||
|
A CACHEDIR.TAG file gets added to the cache directory.
|
|
@ -33,6 +33,13 @@ which provides the `--lf` and `--ff` options, as well as the `cache` fixture.
|
||||||
See [the docs](https://docs.pytest.org/en/latest/cache.html) for more information.
|
See [the docs](https://docs.pytest.org/en/latest/cache.html) for more information.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
CACHEDIR_TAG_CONTENT = b"""\
|
||||||
|
Signature: 8a477f597d28d172789f06886806bc55
|
||||||
|
# This file is a cache directory tag created by pytest.
|
||||||
|
# For information about cache directory tags, see:
|
||||||
|
# http://www.bford.info/cachedir/spec.html
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
class Cache(object):
|
class Cache(object):
|
||||||
|
@ -140,6 +147,10 @@ class Cache(object):
|
||||||
msg = u"# Created by pytest automatically.\n*"
|
msg = u"# Created by pytest automatically.\n*"
|
||||||
gitignore_path.write_text(msg, encoding="UTF-8")
|
gitignore_path.write_text(msg, encoding="UTF-8")
|
||||||
|
|
||||||
|
cachedir_tag_path = self._cachedir.joinpath("CACHEDIR.TAG")
|
||||||
|
if not cachedir_tag_path.is_file():
|
||||||
|
cachedir_tag_path.write_bytes(CACHEDIR_TAG_CONTENT)
|
||||||
|
|
||||||
|
|
||||||
class LFPlugin(object):
|
class LFPlugin(object):
|
||||||
""" Plugin which implements the --lf (run last-failing) option """
|
""" Plugin which implements the --lf (run last-failing) option """
|
||||||
|
|
|
@ -925,3 +925,15 @@ def test_does_not_create_boilerplate_in_existing_dirs(testdir):
|
||||||
assert os.path.isdir("v") # cache contents
|
assert os.path.isdir("v") # cache contents
|
||||||
assert not os.path.exists(".gitignore")
|
assert not os.path.exists(".gitignore")
|
||||||
assert not os.path.exists("README.md")
|
assert not os.path.exists("README.md")
|
||||||
|
|
||||||
|
|
||||||
|
def test_cachedir_tag(testdir):
|
||||||
|
"""Ensure we automatically create CACHEDIR.TAG file in the pytest_cache directory (#4278)."""
|
||||||
|
from _pytest.cacheprovider import Cache
|
||||||
|
from _pytest.cacheprovider import CACHEDIR_TAG_CONTENT
|
||||||
|
|
||||||
|
config = testdir.parseconfig()
|
||||||
|
cache = Cache.for_config(config)
|
||||||
|
cache.set("foo", "bar")
|
||||||
|
cachedir_tag_path = cache._cachedir.joinpath("CACHEDIR.TAG")
|
||||||
|
assert cachedir_tag_path.read_bytes() == CACHEDIR_TAG_CONTENT
|
||||||
|
|
Loading…
Reference in New Issue