From 53d4710c6287fc3e78c2bc1704bd702d05a8b6de Mon Sep 17 00:00:00 2001 From: avirlrma Date: Thu, 21 Jun 2018 14:25:00 +0530 Subject: [PATCH] added tests for .pytest_cache README Helper class to check if readme exists in .pytest_cache directory Tests to check for readme when tests pass and when they fail --- src/_pytest/cacheprovider.py | 9 +++----- testing/test_cacheREADME.py | 42 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 testing/test_cacheREADME.py diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py index ff2d1e285..b1904fbb1 100755 --- a/src/_pytest/cacheprovider.py +++ b/src/_pytest/cacheprovider.py @@ -18,7 +18,6 @@ from os.path import sep as _sep, altsep as _altsep class Cache(object): - def __init__(self, config): self.config = config self._cachedir = Cache.cache_dir_from_config(config) @@ -106,7 +105,7 @@ class Cache(object): self._ensure_readme() def _ensure_readme(self): - content_readme = '''# pytest cache directory # + 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. @@ -114,7 +113,7 @@ 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): @@ -215,9 +214,7 @@ class NFPlugin(object): items[:] = self._get_increasing_order( six.itervalues(new_items) - ) + self._get_increasing_order( - six.itervalues(other_items) - ) + ) + self._get_increasing_order(six.itervalues(other_items)) self.cached_nodeids = [x.nodeid for x in items if isinstance(x, pytest.Item)] def _get_increasing_order(self, items): diff --git a/testing/test_cacheREADME.py b/testing/test_cacheREADME.py new file mode 100644 index 000000000..fe8879bd2 --- /dev/null +++ b/testing/test_cacheREADME.py @@ -0,0 +1,42 @@ +from __future__ import absolute_import, division, print_function +import sys +import py +import _pytest +import pytest +import os +import shutil + +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 + """ + ) + ) + result = testdir.runpytest() + assert self.check_readme(testdir) == True + + def test_readme_failed(self, testdir): + testdir.tmpdir.join("test_a.py").write( + _pytest._code.Source( + """ + def test_always_passes(): + assert 0 + """ + ) + ) + result = testdir.runpytest() + assert self.check_readme(testdir) == True