1414import pytest
1515import json
1616from os .path import sep as _sep , altsep as _altsep
17- from textwrap import dedent
17+ import shutil
1818
1919from . import paths
2020from .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
2435class 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
125124class 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" )
0 commit comments