handle access errors when writing cache files silently as pytest warning, fixes #1039
This commit is contained in:
parent
bf9b94595c
commit
29f4da93d4
|
@ -69,8 +69,20 @@ class Cache(object):
|
|||
like e. g. lists of dictionaries.
|
||||
"""
|
||||
path = self._getvaluepath(key)
|
||||
try:
|
||||
path.dirpath().ensure_dir()
|
||||
with path.open("w") as f:
|
||||
except (py.error.EEXIST, py.error.EACCES):
|
||||
self.config.warn(
|
||||
code='I9', message='cache could not create cache path %s' % (path,)
|
||||
)
|
||||
return
|
||||
try:
|
||||
f = path.open('w')
|
||||
except py.error.ENOTDIR:
|
||||
self.config.warn(
|
||||
code='I9', message='cache could not write path %s' % (path,))
|
||||
else:
|
||||
with f:
|
||||
self.trace("cache-write %s: %r" % (key, value,))
|
||||
json.dump(value, f, indent=2, sort_keys=True)
|
||||
|
||||
|
|
|
@ -25,6 +25,21 @@ class TestNewAPI:
|
|||
val = config.cache.get("key/name", -2)
|
||||
assert val == -2
|
||||
|
||||
def test_cache_writefail_cachfile_silent(self, testdir):
|
||||
testdir.makeini("[pytest]")
|
||||
testdir.tmpdir.join('.cache').write('gone wrong')
|
||||
config = testdir.parseconfigure()
|
||||
cache = config.cache
|
||||
cache.set('test/broken', [])
|
||||
|
||||
def test_cache_writefail_permissions(selfself, testdir):
|
||||
testdir.makeini("[pytest]")
|
||||
testdir.tmpdir.ensure_dir('.cache').chmod(0)
|
||||
config = testdir.parseconfigure()
|
||||
cache = config.cache
|
||||
cache.set('test/broken', [])
|
||||
|
||||
|
||||
def test_config_cache(self, testdir):
|
||||
testdir.makeconftest("""
|
||||
def pytest_configure(config):
|
||||
|
|
Loading…
Reference in New Issue