From c672bfa32ea9e3602225eb45b0ffdc4cdb1ce47a Mon Sep 17 00:00:00 2001 From: avirlrma Date: Thu, 21 Jun 2018 17:43:10 +0530 Subject: [PATCH] added changelog entry moved cache readme tests to test_cacheprovider.py --- changelog/3519.feature.rst | 1 + src/_pytest/cacheprovider.py | 15 +++++++++----- testing/test_cacheREADME.py | 39 ----------------------------------- testing/test_cacheprovider.py | 30 ++++++++++++++++++++++++++- 4 files changed, 40 insertions(+), 45 deletions(-) create mode 100644 changelog/3519.feature.rst delete mode 100644 testing/test_cacheREADME.py diff --git a/changelog/3519.feature.rst b/changelog/3519.feature.rst new file mode 100644 index 000000000..4526c63ad --- /dev/null +++ b/changelog/3519.feature.rst @@ -0,0 +1 @@ +now `.pytest_cache` is created with a README.md to indicate it's usage,options etc. \ No newline at end of file diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py index 5d9b58a65..10564ab1d 100755 --- a/src/_pytest/cacheprovider.py +++ b/src/_pytest/cacheprovider.py @@ -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): @@ -106,15 +107,19 @@ class Cache(object): self._ensure_readme() def _ensure_readme(self): - content_readme = """# 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. + content_readme = dedent( + """\ + # pytest cache directory # -**Do not** commit this to version control. + This directory contains data from the pytest's cache plugin,\ + 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. + **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): diff --git a/testing/test_cacheREADME.py b/testing/test_cacheREADME.py deleted file mode 100644 index 3e5673609..000000000 --- a/testing/test_cacheREADME.py +++ /dev/null @@ -1,39 +0,0 @@ -from __future__ import absolute_import, division, print_function -import _pytest - -pytest_plugins = ("pytester",) - - -class Helper(object): - - def check_readme(self, testdir): - config = testdir.parseconfigure() - readme = config.cache._cachedir.join("README.md") - return readme.isfile() - - -class TestReadme(Helper): - - def test_readme_passed(self, testdir): - testdir.tmpdir.join("test_a.py").write( - _pytest._code.Source( - """ - def test_always_passes(): - assert 1 - """ - ) - ) - testdir.runpytest() - assert self.check_readme(testdir) is True - - def test_readme_failed(self, testdir): - testdir.tmpdir.join("test_a.py").write( - _pytest._code.Source( - """ - def test_always_passes(): - assert 0 - """ - ) - ) - testdir.runpytest() - assert self.check_readme(testdir) is True diff --git a/testing/test_cacheprovider.py b/testing/test_cacheprovider.py index 33d1dd844..4a7c25aa0 100644 --- a/testing/test_cacheprovider.py +++ b/testing/test_cacheprovider.py @@ -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