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
This commit is contained in:
avirlrma 2018-06-21 14:25:00 +05:30
parent 31f089db6a
commit 53d4710c62
2 changed files with 45 additions and 6 deletions

View File

@ -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):

View File

@ -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