Skip to content

Commit ee30bf4

Browse files
rebase onto readme addition
1 parent 603df1e commit ee30bf4

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

src/_pytest/cacheprovider.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,22 @@
1414
import pytest
1515
import json
1616
from os.path import sep as _sep, altsep as _altsep
17-
from textwrap import dedent
17+
import shutil
1818

1919
from . import paths
2020
from .compat import _PY2 as PY2
2121

22+
README_CONTENT = u"""\
23+
# pytest cache directory #
24+
25+
This directory contains data from the pytest's cache plugin,
26+
which provides the `--lf` and `--ff` options, as well as the `cache` fixture.
27+
28+
**Do not** commit this to version control.
29+
30+
See [the docs](https://docs.pytest.org/en/latest/cache.html) for more information.
31+
"""
32+
2233

2334
@attr.s
2435
class Cache(object):
@@ -104,22 +115,10 @@ def set(self, key, value):
104115

105116
def _ensure_readme(self):
106117

107-
content_readme = dedent(
108-
"""\
109-
# pytest cache directory #
110-
111-
This directory contains data from the pytest's cache plugin,
112-
which provides the `--lf` and `--ff` options, as well as the `cache` fixture.
113-
114-
**Do not** commit this to version control.
115-
116-
See [the docs](https://docs.pytest.org/en/latest/cache.html) for more information.
117-
"""
118-
)
119-
if self._cachedir.check(dir=True):
120-
readme_path = self._cachedir.join("README.md")
121-
if not readme_path.check(file=True):
122-
readme_path.write(content_readme)
118+
if self._cachedir.is_dir():
119+
readme_path = self._cachedir / "README.md"
120+
if not readme_path.is_file():
121+
readme_path.write_text(README_CONTENT)
123122

124123

125124
class LFPlugin(object):
@@ -330,7 +329,7 @@ def cacheshow(config, session):
330329
return 0
331330
dummy = object()
332331
basedir = config.cache._cachedir
333-
vdir = basedir.joinpath("v")
332+
vdir = basedir / "v"
334333
tw.sep("-", "cache values")
335334
for valpath in sorted(x for x in vdir.rglob("*") if x.is_file()):
336335
key = "/".join(valpath.relative_to(vdir).parts)
@@ -342,7 +341,7 @@ def cacheshow(config, session):
342341
for line in pformat(val).splitlines():
343342
tw.line(" " + line)
344343

345-
ddir = basedir.joinpath("d")
344+
ddir = basedir / "d"
346345
if ddir.is_dir():
347346
contents = sorted(ddir.rglob("*"))
348347
tw.sep("-", "cache directories")

testing/test_cacheprovider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,8 @@ class TestReadme(object):
826826

827827
def check_readme(self, testdir):
828828
config = testdir.parseconfigure()
829-
readme = config.cache._cachedir.join("README.md")
830-
return readme.isfile()
829+
readme = config.cache._cachedir.joinpath("README.md")
830+
return readme.is_file()
831831

832832
def test_readme_passed(self, testdir):
833833
testdir.makepyfile(

0 commit comments

Comments
 (0)