Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#4278 Added a CACHEDIR.TAG file to the cache directory #4504

Merged
merged 2 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/4278.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added a CACHEDIR.TAG file to the cache directory
11 changes: 11 additions & 0 deletions src/_pytest/cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
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
class Cache(object):
Expand Down Expand Up @@ -140,6 +147,10 @@ def _ensure_supporting_files(self):
msg = u"# Created by pytest automatically.\n*"
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):
""" Plugin which implements the --lf (run last-failing) option """
Expand Down
12 changes: 12 additions & 0 deletions testing/test_cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -925,3 +925,15 @@ def test_does_not_create_boilerplate_in_existing_dirs(testdir):
assert os.path.isdir("v") # cache contents
assert not os.path.exists(".gitignore")
assert not os.path.exists("README.md")


feuillemorte marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be just asserted in some existing test (to not increase number of tests unnecessarily).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps mark the PR as "Changes requested" @blueyed? This makes clear that there are still issues to address here, both to @feuillemorte and by us (I almost merged this until I saw this comment).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it was just a comment/suggestion - feel free to merge it already.