Fix Cache.warn function to issue a "config" warning

This commit is contained in:
Bruno Oliveira 2018-09-04 15:52:44 -03:00
parent 438f7a1254
commit 3db76ccf3d
1 changed files with 5 additions and 4 deletions

View File

@ -6,7 +6,6 @@ ignores the external pytest-cache
""" """
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
from collections import OrderedDict from collections import OrderedDict
import warnings
import py import py
import six import six
@ -34,6 +33,7 @@ See [the docs](https://docs.pytest.org/en/latest/cache.html) for more informatio
@attr.s @attr.s
class Cache(object): class Cache(object):
_cachedir = attr.ib(repr=False) _cachedir = attr.ib(repr=False)
_config = attr.ib(repr=False)
@classmethod @classmethod
def for_config(cls, config): def for_config(cls, config):
@ -41,17 +41,18 @@ class Cache(object):
if config.getoption("cacheclear") and cachedir.exists(): if config.getoption("cacheclear") and cachedir.exists():
shutil.rmtree(str(cachedir)) shutil.rmtree(str(cachedir))
cachedir.mkdir() cachedir.mkdir()
return cls(cachedir) return cls(cachedir, config)
@staticmethod @staticmethod
def cache_dir_from_config(config): def cache_dir_from_config(config):
return paths.resolve_from_str(config.getini("cache_dir"), config.rootdir) return paths.resolve_from_str(config.getini("cache_dir"), config.rootdir)
def warn(self, fmt, **args): def warn(self, fmt, **args):
from _pytest.warnings import _issue_config_warning
from _pytest.warning_types import PytestWarning from _pytest.warning_types import PytestWarning
warnings.warn( _issue_config_warning(
message=fmt.format(**args) if args else fmt, category=PytestWarning PytestWarning(fmt.format(**args) if args else fmt), self._config
) )
def makedir(self, name): def makedir(self, name):