From 86fea8926e1eb15eaa1a6ee49e495caeb1ec2b18 Mon Sep 17 00:00:00 2001 From: Thorsten Lockert Date: Mon, 17 Oct 2016 16:58:06 -0700 Subject: [PATCH] Allow execution without cacheprovider If caching has been explicityly disabled, allow running. Fixes #16 --- CHANGELOG | 6 ++++++ pytest_flake8.py | 13 +++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 68ab534..24e9cbd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +0.8 +--- + +- Allow running with not cacheprovider +- Modernize use of fixtures in tests + 0.7 --- diff --git a/pytest_flake8.py b/pytest_flake8.py index 22b8831..b5789ac 100644 --- a/pytest_flake8.py +++ b/pytest_flake8.py @@ -51,7 +51,8 @@ def pytest_configure(config): config._flake8showshource = config.getini("flake8-show-source") config._flake8statistics = config.getini("flake8-statistics") config._flake8exts = config.getini("flake8-extensions") - config._flake8mtimes = config.cache.get(HISTKEY, {}) + if hasattr(config, 'cache'): + config._flake8mtimes = config.cache.get(HISTKEY, {}) def pytest_collect_file(path, parent): @@ -93,7 +94,10 @@ def __init__(self, path, parent, flake8ignore, maxlength, self.statistics = statistics def setup(self): - flake8mtimes = self.config._flake8mtimes + if hasattr(self.config, "_flake8mtimes"): + flake8mtimes = self.config._flake8mtimes + else: + flake8mtimes = {} self._flake8mtime = self.fspath.mtime() old = flake8mtimes.get(str(self.fspath), (0, [])) if old == [self._flake8mtime, self.flake8ignore]: @@ -113,8 +117,9 @@ def runtest(self): raise Flake8Error(out, err) # update mtime only if test passed # otherwise failures would not be re-run next time - self.config._flake8mtimes[str(self.fspath)] = (self._flake8mtime, - self.flake8ignore) + if hasattr(self.config, "_flake8mtimes"): + self.config._flake8mtimes[str(self.fspath)] = (self._flake8mtime, + self.flake8ignore) def repr_failure(self, excinfo): if excinfo.errisinstance(Flake8Error):