Merge pull request #3608 from avirlrma/features

add reamde for .pytest_cache
This commit is contained in:
Bruno Oliveira 2018-06-21 21:05:23 -03:00 committed by GitHub
commit de98939ebf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 1 deletions

View File

@ -0,0 +1 @@
Now a ``README.md`` file is created in ``.pytest_cache`` to make it clear why the directory exists.

View File

@ -15,6 +15,7 @@ import pytest
import json
import os
from os.path import sep as _sep, altsep as _altsep
from textwrap import dedent
class Cache(object):
@ -103,6 +104,26 @@ class Cache(object):
with f:
self.trace("cache-write %s: %r" % (key, value))
json.dump(value, f, indent=2, sort_keys=True)
self._ensure_readme()
def _ensure_readme(self):
content_readme = dedent(
"""\
# pytest cache directory #
This directory contains data from the pytest's cache plugin,
which provides the `--lf` and `--ff` options, as well as the `cache` fixture.
**Do not** commit this to version control.
See [the docs](https://docs.pytest.org/en/latest/cache.html) for more information.
"""
)
if self._cachedir.check(dir=True):
readme_path = self._cachedir.join("README.md")
if not readme_path.check(file=True):
readme_path.write(content_readme)
class LFPlugin(object):

View File

@ -6,7 +6,7 @@ import pytest
import os
import shutil
pytest_plugins = "pytester",
pytest_plugins = ("pytester",)
class TestNewAPI(object):
@ -818,3 +818,31 @@ class TestNewFirst(object):
"*test_1/test_1.py::test_1[2*",
]
)
class TestReadme(object):
def check_readme(self, testdir):
config = testdir.parseconfigure()
readme = config.cache._cachedir.join("README.md")
return readme.isfile()
def test_readme_passed(self, testdir):
testdir.makepyfile(
"""
def test_always_passes():
assert 1
"""
)
testdir.runpytest()
assert self.check_readme(testdir) is True
def test_readme_failed(self, testdir):
testdir.makepyfile(
"""
def test_always_passes():
assert 0
"""
)
testdir.runpytest()
assert self.check_readme(testdir) is True