pytest-flake8-1.0.6/0000755000076500000240000000000013656621350014475 5ustar tholostaff00000000000000pytest-flake8-1.0.6/PKG-INFO0000644000076500000240000001421113656621350015571 0ustar tholostaff00000000000000Metadata-Version: 1.1 Name: pytest-flake8 Version: 1.0.6 Summary: pytest plugin to check FLAKE8 requirements Home-page: https://github.com/tholo/pytest-flake8 Author: Thorsten Lockert Author-email: tholo@sigmasoft.com License: BSD License Description: pytest plugin for efficiently checking PEP8 compliance ====================================================== .. image:: https://img.shields.io/pypi/v/pytest-flake8.svg :target: https://pypi.python.org/pypi/pytest-flake8 .. image:: https://img.shields.io/pypi/pyversions/pytest-flake8.svg :target: https://pypi.python.org/pypi/pytest-flake8 .. image:: https://img.shields.io/pypi/implementation/pytest-flake8.svg :target: https://pypi.python.org/pypi/pytest-flake8 .. image:: https://img.shields.io/pypi/status/pytest-flake8.svg :target: https://pypi.python.org/pypi/pytest-flake8 .. image:: https://travis-ci.org/tholo/pytest-flake8.svg?branch=master :target: https://travis-ci.org/tholo/pytest-flake8 .. image:: https://img.shields.io/github/issues/tholo/pytest-flake8.svg :target: https://github.com/tholo/pytest-flake8/issues .. image:: https://img.shields.io/github/issues-pr/tholo/pytest-flake8.svg :target: https://github.com/tholo/pytest-flake8/pulls Usage ----- Install by running the command:: pip install pytest-flake8 After installing it, when you run tests with the option:: pytest --flake8 every file ending in ``.py`` will be discovered and checked with flake8. .. note:: If optional flake8 plugins are installed, those will be used automatically. No provisions have been made for configuring these via `pytest`_. .. warning:: Running flake8 tests on your project is likely to cause a number of issues. The plugin allows one to configure on a per-project and per-file basis which errors or warnings to ignore, see flake8-ignore_. .. _flake8-ignore: Configuring FLAKE8 options per project and file ----------------------------------------------- Maximum line length can be configured for the whole project by adding a ``flake8-max-line-length`` option to your ``setup.cfg`` or ``tox.ini`` file like this:: # content of setup.cfg [pytest] flake8-max-line-length = 99 Note that the default will be what naturally comes with `flake8`_ (which it turn gets its default from `pycodestyle`_). You may configure flake8-checking options for your project by adding an ``flake8-ignore`` entry to your ``setup.cfg`` or ``tox.ini`` file like this:: # content of setup.cfg [pytest] flake8-ignore = E201 E231 This would globally prevent complaints about two whitespace issues. Rerunning with the above example will now look better:: $ pytest -q --flake8 collecting ... collected 1 items . 1 passed in 0.01 seconds If you have some files where you want to specifically ignore some errors or warnings you can start a flake8-ignore line with a glob-pattern and a space-separated list of codes:: # content of setup.cfg [pytest] flake8-ignore = *.py E201 doc/conf.py ALL So if you have a conf.py like this:: # content of doc/conf.py func ( [1,2,3]) #this line lots PEP8 errors :) then running again with the previous example will show a single failure and it will ignore doc/conf.py alltogether:: $ pytest --flake8 -v # verbose shows what is ignored ======================================= test session starts ======================================== platform darwin -- Python 2.7.6 -- py-1.4.26 -- pytest-2.7.0 -- /Users/tholo/Source/pytest/bin/python cachedir: /Users/tholo/Source/pytest/src/verify/.cache rootdir: /Users/tholo/Source/angular/src/verify, inifile: setup.cfg plugins: flake8, cache collected 1 items myfile.py PASSED ========================================= 1 passed in 0.00 seconds ========================================= Note that doc/conf.py was not considered or imported. Notes ----- The repository of this plugin is at https://github.com/tholo/pytest-flake8 For more info on `pytest`_ see http://pytest.org The code is partially based on Ronny Pfannschmidt's `pytest-codecheckers`_ plugin. .. _`pytest`: http://pytest.org .. _`flake8`: https://pypi.python.org/pypi/flake8 .. _`pycodestyle`: https://pypi.python.org/pypi/pycodestyle .. _`pytest-codecheckers`: https://pypi.python.org/pypi/pytest-codecheckers Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Software Development Classifier: Topic :: Software Development :: Quality Assurance Classifier: Topic :: Software Development :: Testing pytest-flake8-1.0.6/test_flake8.py0000644000076500000240000001214413656621347017270 0ustar tholostaff00000000000000# coding=utf8 """Unit tests for flake8 pytest plugin.""" from __future__ import print_function import py import pytest pytest_plugins = "pytester", def test_version(): """Verify we can get version.""" import pytest_flake8 assert pytest_flake8.__version__ class TestIgnores: """Test ignores.""" @pytest.fixture def example(self, request): """Create a test file.""" testdir = request.getfixturevalue("testdir") import sys print(testdir, file=sys.stderr) p = testdir.makepyfile("") p.write("class AClass:\n pass\n \n\n# too many spaces") return p def test_ignores(self, tmpdir): """Verify parsing of ignore statements.""" from pytest_flake8 import Ignorer ignores = ["E203", "b/?.py E204 W205", "z.py ALL", "*.py E300"] ign = Ignorer(ignores) assert ign(tmpdir.join("a/b/x.py")) == "E203 E204 W205 E300".split() assert ign(tmpdir.join("a/y.py")) == "E203 E300".split() assert ign(tmpdir.join("a/z.py")) is None def test_default_flake8_ignores(self, testdir): testdir.makeini(""" [pytest] markers = flake8 [flake8] ignore = E203 *.py E300 tests/*.py ALL E203 # something """) testdir.tmpdir.ensure("xy.py") testdir.tmpdir.ensure("tests/hello.py") result = testdir.runpytest("--flake8", "-s") result.assert_outcomes(passed=2) result.stdout.fnmatch_lines([ "*collected 2*", "*xy.py .*", "*2 passed*", ]) def test_ignores_all(self, testdir): """Verify success when all errors are ignored.""" testdir.makeini(""" [pytest] markers = flake8 flake8-ignore = E203 *.py E300 tests/*.py ALL E203 # something """) testdir.tmpdir.ensure("xy.py") testdir.tmpdir.ensure("tests/hello.py") result = testdir.runpytest("--flake8", "-s") result.assert_outcomes(passed=1) result.stdout.fnmatch_lines([ "*collected 1*", "*xy.py .*", "*1 passed*", ]) def test_w293w292(self, testdir, example): result = testdir.runpytest("--flake8", ) result.stdout.fnmatch_lines([ # "*plugins*flake8*", "*W293*", "*W292*", ]) result.assert_outcomes(failed=1) def test_mtime_caching(self, testdir, example): testdir.tmpdir.ensure("hello.py") result = testdir.runpytest("--flake8", ) result.stdout.fnmatch_lines([ # "*plugins*flake8*", "*W293*", "*W292*", ]) result.assert_outcomes(passed=1, failed=1) result = testdir.runpytest("--flake8", ) result.stdout.fnmatch_lines([ "*W293*", "*W292*", ]) result.assert_outcomes(skipped=1, failed=1) testdir.makeini(""" [pytest] flake8-ignore = *.py W293 W292 W391 """) result = testdir.runpytest("--flake8", ) result.assert_outcomes(passed=2) def test_extensions(testdir): testdir.makeini(""" [pytest] markers = flake8 flake8-extensions = .py .pyx """) testdir.makefile(".pyx", """ @cfunc def f(): pass """) result = testdir.runpytest("--flake8") result.stdout.fnmatch_lines([ "*collected 1*", ]) result.assert_outcomes(failed=1) def test_ok_verbose(testdir): p = testdir.makepyfile(""" class AClass: pass """) p = p.write(p.read() + "\n") result = testdir.runpytest("--flake8", "--verbose") result.stdout.fnmatch_lines([ "*test_ok_verbose*", ]) result.assert_outcomes(passed=1) def test_keyword_match(testdir): testdir.makepyfile(""" def test_hello(): a=[ 1,123] # """) result = testdir.runpytest("--flake8", "-mflake8") result.stdout.fnmatch_lines([ "*E201*", "*1 failed*", ]) result.assert_outcomes(failed=1) @pytest.mark.xfail("sys.platform == 'win32'") def test_unicode_error(testdir): x = testdir.tmpdir.join("x.py") import codecs f = codecs.open(str(x), "w", encoding="utf8") f.write(py.builtin._totext(""" # coding=utf8 accent_map = { u'\\xc0': 'a', # À -> a non-ascii comment crashes it } """, "utf8")) f.close() # result = testdir.runpytest("--flake8", x, "-s") # result.stdout.fnmatch_lines("*non-ascii comment*") @pytest.mark.xfail(reason="flake8 is not properly registered as a marker") def test_strict(testdir): testdir.makepyfile("") result = testdir.runpytest("--strict", "-mflake8") result.assert_outcomes(passed=1) def test_junit_classname(testdir): testdir.makepyfile("") result = testdir.runpytest("--flake8", "--junit-xml=TEST.xml") junit = testdir.tmpdir.join("TEST.xml") with open(str(junit)) as j_file: j_text = j_file.read() result.assert_outcomes(passed=1) assert 'classname=""' not in j_text pytest-flake8-1.0.6/LICENSE0000644000076500000240000000235213656621347015512 0ustar tholostaff00000000000000Copyright (c) 2015 Thorsten Lockert All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. pytest-flake8-1.0.6/CHANGELOG0000644000076500000240000000343513656621347015722 0ustar tholostaff000000000000001.0.6 ----- - Fix compatibility with flake8 >= 3.8, from @marc 1.0.5 ----- - Fix deprecation warning; from @jonasundderwolf 1.0.4 ----- - Support flake8 3.7+ by checking existence of "app.make_notifier"; from jirikuncar@github - More fixes for Travis CI -- properly specify Python versions, in particular for pypy (and fix a typo) 1.0.3 ----- - Don't use long deprecated functions from pytest, broke with pytest 4.1.0 - Fix typo that caused some tests to not run as expected - Run Travis CI tests against Python 3.7, and fix some issues with current tox 1.0.2 ----- - Test on Python 3.7 - Escape a regex tring with r"" 1.0.1 ----- - Correct junit XML output for pytest 3.5.x 1.0.0 ----- - Honor ignore settings in default flake8 config section; from brianbruggeman@github - Improve junit XML output; from Struan Judd 0.9.1 ----- - Do continuous integration with Travis; from alex-dr@github - Declare compatibility with Python 3.6 0.9 --- - Extend options already loaded instead of replacing them; from mforbes@github - Correct some issues preventing proper operation with flake8 3.5.0; from jezdez@github - Register pytest marker for flake8; from alex-dr@github 0.8, 0.8.1 ---------- - Allow running with no cacheprovider - Modernize use of fixtures in tests 0.7 --- - Added new options "flake8-max-complexity", "flake8-show-source" and "flake8-statistics" 0.6 --- - Update for flake8 3.x 0.5 --- - Fix rendering of rST; from Ken Dreyer 0.4 --- - Really fix cache usage; had a comparison between tuple and list which always failed 0.3 --- - Use integrated pytest cache instead of separate pytest-cache module (which is now integrated) - Use documented hooks for start and end of a test run 0.2 --- - Added ability to override maximum line length 0.1 --- - initial release pytest-flake8-1.0.6/MANIFEST.in0000644000076500000240000000021413656621347016236 0ustar tholostaff00000000000000include CHANGELOG include README.rst include setup.py include tox.ini include LICENSE include test_flake8.py graft doc graft test_flake8.py pytest-flake8-1.0.6/setup.py0000644000076500000240000000262313656621347016220 0ustar tholostaff00000000000000# -*- coding: utf-8 -*- """Install package.""" from setuptools import setup setup( name='pytest-flake8', version='1.0.6', description='pytest plugin to check FLAKE8 requirements', long_description=open("README.rst").read(), classifiers=[ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development", "Topic :: Software Development :: Quality Assurance", "Topic :: Software Development :: Testing", ], license="BSD License", author='Thorsten Lockert', author_email='tholo@sigmasoft.com', url='https://github.com/tholo/pytest-flake8', py_modules=[ 'pytest_flake8', ], entry_points={ 'pytest11': ['flake8 = pytest_flake8'], }, install_requires=[ 'flake8>=3.5', 'pytest>=3.5', ], ) pytest-flake8-1.0.6/pytest_flake8.egg-info/0000755000076500000240000000000013656621350020751 5ustar tholostaff00000000000000pytest-flake8-1.0.6/pytest_flake8.egg-info/PKG-INFO0000644000076500000240000001421113656621347022053 0ustar tholostaff00000000000000Metadata-Version: 1.1 Name: pytest-flake8 Version: 1.0.6 Summary: pytest plugin to check FLAKE8 requirements Home-page: https://github.com/tholo/pytest-flake8 Author: Thorsten Lockert Author-email: tholo@sigmasoft.com License: BSD License Description: pytest plugin for efficiently checking PEP8 compliance ====================================================== .. image:: https://img.shields.io/pypi/v/pytest-flake8.svg :target: https://pypi.python.org/pypi/pytest-flake8 .. image:: https://img.shields.io/pypi/pyversions/pytest-flake8.svg :target: https://pypi.python.org/pypi/pytest-flake8 .. image:: https://img.shields.io/pypi/implementation/pytest-flake8.svg :target: https://pypi.python.org/pypi/pytest-flake8 .. image:: https://img.shields.io/pypi/status/pytest-flake8.svg :target: https://pypi.python.org/pypi/pytest-flake8 .. image:: https://travis-ci.org/tholo/pytest-flake8.svg?branch=master :target: https://travis-ci.org/tholo/pytest-flake8 .. image:: https://img.shields.io/github/issues/tholo/pytest-flake8.svg :target: https://github.com/tholo/pytest-flake8/issues .. image:: https://img.shields.io/github/issues-pr/tholo/pytest-flake8.svg :target: https://github.com/tholo/pytest-flake8/pulls Usage ----- Install by running the command:: pip install pytest-flake8 After installing it, when you run tests with the option:: pytest --flake8 every file ending in ``.py`` will be discovered and checked with flake8. .. note:: If optional flake8 plugins are installed, those will be used automatically. No provisions have been made for configuring these via `pytest`_. .. warning:: Running flake8 tests on your project is likely to cause a number of issues. The plugin allows one to configure on a per-project and per-file basis which errors or warnings to ignore, see flake8-ignore_. .. _flake8-ignore: Configuring FLAKE8 options per project and file ----------------------------------------------- Maximum line length can be configured for the whole project by adding a ``flake8-max-line-length`` option to your ``setup.cfg`` or ``tox.ini`` file like this:: # content of setup.cfg [pytest] flake8-max-line-length = 99 Note that the default will be what naturally comes with `flake8`_ (which it turn gets its default from `pycodestyle`_). You may configure flake8-checking options for your project by adding an ``flake8-ignore`` entry to your ``setup.cfg`` or ``tox.ini`` file like this:: # content of setup.cfg [pytest] flake8-ignore = E201 E231 This would globally prevent complaints about two whitespace issues. Rerunning with the above example will now look better:: $ pytest -q --flake8 collecting ... collected 1 items . 1 passed in 0.01 seconds If you have some files where you want to specifically ignore some errors or warnings you can start a flake8-ignore line with a glob-pattern and a space-separated list of codes:: # content of setup.cfg [pytest] flake8-ignore = *.py E201 doc/conf.py ALL So if you have a conf.py like this:: # content of doc/conf.py func ( [1,2,3]) #this line lots PEP8 errors :) then running again with the previous example will show a single failure and it will ignore doc/conf.py alltogether:: $ pytest --flake8 -v # verbose shows what is ignored ======================================= test session starts ======================================== platform darwin -- Python 2.7.6 -- py-1.4.26 -- pytest-2.7.0 -- /Users/tholo/Source/pytest/bin/python cachedir: /Users/tholo/Source/pytest/src/verify/.cache rootdir: /Users/tholo/Source/angular/src/verify, inifile: setup.cfg plugins: flake8, cache collected 1 items myfile.py PASSED ========================================= 1 passed in 0.00 seconds ========================================= Note that doc/conf.py was not considered or imported. Notes ----- The repository of this plugin is at https://github.com/tholo/pytest-flake8 For more info on `pytest`_ see http://pytest.org The code is partially based on Ronny Pfannschmidt's `pytest-codecheckers`_ plugin. .. _`pytest`: http://pytest.org .. _`flake8`: https://pypi.python.org/pypi/flake8 .. _`pycodestyle`: https://pypi.python.org/pypi/pycodestyle .. _`pytest-codecheckers`: https://pypi.python.org/pypi/pytest-codecheckers Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2 Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: 3.6 Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Software Development Classifier: Topic :: Software Development :: Quality Assurance Classifier: Topic :: Software Development :: Testing pytest-flake8-1.0.6/pytest_flake8.egg-info/SOURCES.txt0000644000076500000240000000050313656621350022633 0ustar tholostaff00000000000000CHANGELOG LICENSE MANIFEST.in README.rst pytest_flake8.py setup.cfg setup.py test_flake8.py tox.ini pytest_flake8.egg-info/PKG-INFO pytest_flake8.egg-info/SOURCES.txt pytest_flake8.egg-info/dependency_links.txt pytest_flake8.egg-info/entry_points.txt pytest_flake8.egg-info/requires.txt pytest_flake8.egg-info/top_level.txtpytest-flake8-1.0.6/pytest_flake8.egg-info/entry_points.txt0000644000076500000240000000004313656621347024252 0ustar tholostaff00000000000000[pytest11] flake8 = pytest_flake8 pytest-flake8-1.0.6/pytest_flake8.egg-info/requires.txt0000644000076500000240000000003013656621347023350 0ustar tholostaff00000000000000flake8>=3.5 pytest>=3.5 pytest-flake8-1.0.6/pytest_flake8.egg-info/top_level.txt0000644000076500000240000000001613656621347023506 0ustar tholostaff00000000000000pytest_flake8 pytest-flake8-1.0.6/pytest_flake8.egg-info/dependency_links.txt0000644000076500000240000000000113656621347025025 0ustar tholostaff00000000000000 pytest-flake8-1.0.6/tox.ini0000644000076500000240000000067213656621347016023 0ustar tholostaff00000000000000[tox] envlist=py27,py36-pytesttrunk,py36-xdist,py34,py35,py36,py37,py38,pypy,pypy3 [testenv] deps=pytest commands= pytest --junitxml={envlogdir}/junit-{envname}.xml {posargs} [testenv:py36-pytesttrunk] pip_pre=true deps=pytest [testenv:py36-xdist] deps={[testenv]deps} pytest-xdist commands= pytest -n3 --junitxml={envlogdir}/junit-{envname}.xml {posargs} [pytest] addopts=--flake8 junit_family=xunit1 [flake8] ignore=E128 pytest-flake8-1.0.6/setup.cfg0000644000076500000240000000016613656621350016321 0ustar tholostaff00000000000000[bdist_wheel] universal = true [devpi:upload] formats = bdist_wheel,sdist.tgz [egg_info] tag_build = tag_date = 0 pytest-flake8-1.0.6/pytest_flake8.py0000644000076500000240000001724713656621347017652 0ustar tholostaff00000000000000"""py.test plugin to test with flake8.""" import os import re from flake8.main import application from flake8.options import config import py import pytest __version__ = '0.6' HISTKEY = "flake8/mtimes" def pytest_addoption(parser): """Hook up additional options.""" group = parser.getgroup("general") group.addoption( '--flake8', action='store_true', help="perform some flake8 sanity checks on .py files") parser.addini( "flake8-ignore", type="linelist", help="each line specifies a glob pattern and whitespace " "separated FLAKE8 errors or warnings which will be ignored, " "example: *.py W293") parser.addini( "flake8-max-line-length", help="maximum line length") parser.addini( "flake8-max-complexity", help="McCabe complexity threshold") parser.addini( "flake8-show-source", type="bool", help="show the source generate each error or warning") parser.addini( "flake8-statistics", type="bool", help="count errors and warnings") parser.addini( "flake8-extensions", type="args", default=[".py"], help="a list of file extensions, for example: .py .pyx") def pytest_configure(config): """Start a new session.""" if config.option.flake8: config._flake8ignore = Ignorer(config.getini("flake8-ignore")) config._flake8maxlen = config.getini("flake8-max-line-length") config._flake8maxcomplexity = config.getini("flake8-max-complexity") config._flake8showshource = config.getini("flake8-show-source") config._flake8statistics = config.getini("flake8-statistics") config._flake8exts = config.getini("flake8-extensions") config.addinivalue_line('markers', "flake8: Tests which run flake8.") if hasattr(config, 'cache'): config._flake8mtimes = config.cache.get(HISTKEY, {}) def pytest_collect_file(path, parent): """Filter files down to which ones should be checked.""" config = parent.config if config.option.flake8 and path.ext in config._flake8exts: flake8ignore = config._flake8ignore(path) if flake8ignore is not None: if hasattr(Flake8Item, "from_parent"): item = Flake8Item.from_parent(parent, fspath=path) item.flake8ignore = flake8ignore item.maxlength = config._flake8maxlen item.maxcomplexity = config._flake8maxcomplexity item.showshource = config._flake8showshource item.statistics = config._flake8statistics return item else: return Flake8Item( path, parent, flake8ignore=flake8ignore, maxlength=config._flake8maxlen, maxcomplexity=config._flake8maxcomplexity, showshource=config._flake8showshource, statistics=config._flake8statistics) def pytest_unconfigure(config): """Flush cache at end of run.""" if hasattr(config, "_flake8mtimes"): config.cache.set(HISTKEY, config._flake8mtimes) class Flake8Error(Exception): """ indicates an error during flake8 checks. """ class Flake8Item(pytest.Item, pytest.File): def __init__(self, fspath, parent, flake8ignore=None, maxlength=None, maxcomplexity=None, showshource=None, statistics=None): super(Flake8Item, self).__init__(fspath, parent) self._nodeid += "::FLAKE8" self.add_marker("flake8") self.flake8ignore = flake8ignore self.maxlength = maxlength self.maxcomplexity = maxcomplexity self.showshource = showshource self.statistics = statistics def setup(self): 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]: pytest.skip("file(s) previously passed FLAKE8 checks") def runtest(self): call = py.io.StdCapture.call found_errors, out, err = call( check_file, self.fspath, self.flake8ignore, self.maxlength, self.maxcomplexity, self.showshource, self.statistics) if found_errors: raise Flake8Error(out, err) # update mtime only if test passed # otherwise failures would not be re-run next time if hasattr(self.config, "_flake8mtimes"): self.config._flake8mtimes[str(self.fspath)] = (self._flake8mtime, self.flake8ignore) def repr_failure(self, excinfo): if excinfo.errisinstance(Flake8Error): return excinfo.value.args[0] return super(Flake8Item, self).repr_failure(excinfo) def reportinfo(self): if self.flake8ignore: ignores = "(ignoring %s)" % " ".join(self.flake8ignore) else: ignores = "" return (self.fspath, -1, "FLAKE8-check%s" % ignores) class Ignorer: def __init__(self, ignorelines, coderex=re.compile(r"[EW]\d\d\d")): self.ignores = ignores = [] for line in ignorelines: i = line.find("#") if i != -1: line = line[:i] try: glob, ign = line.split(None, 1) except ValueError: glob, ign = None, line if glob and coderex.match(glob): glob, ign = None, line ign = ign.split() if "ALL" in ign: ign = None if glob and "/" != os.sep and "/" in glob: glob = glob.replace("/", os.sep) ignores.append((glob, ign)) def __call__(self, path): l = [] # noqa: E741 for (glob, ignlist) in self.ignores: if not glob or path.fnmatch(glob): if ignlist is None: return None l.extend(ignlist) return l def check_file(path, flake8ignore, maxlength, maxcomplexity, showshource, statistics): """Run flake8 over a single file, and return the number of failures.""" args = [] if maxlength: args += ['--max-line-length', maxlength] if maxcomplexity: args += ['--max-complexity', maxcomplexity] if showshource: args += ['--show-source'] if statistics: args += ['--statistics'] app = application.Application() if not hasattr(app, 'parse_preliminary_options_and_args'): # flake8 >= 3.8 prelim_opts, remaining_args = app.parse_preliminary_options(args) config_finder = config.ConfigFileFinder( app.program, prelim_opts.append_config, config_file=prelim_opts.config, ignore_config_files=prelim_opts.isolated, ) app.find_plugins(config_finder) app.register_plugin_options() app.parse_configuration_and_cli(config_finder, remaining_args) else: app.parse_preliminary_options_and_args(args) app.make_config_finder() app.find_plugins() app.register_plugin_options() app.parse_configuration_and_cli(args) if flake8ignore: app.options.ignore = flake8ignore app.make_formatter() # fix this if hasattr(app, 'make_notifier'): # removed in flake8 3.7+ app.make_notifier() app.make_guide() app.make_file_checker_manager() app.run_checks([str(path)]) app.formatter.start() app.report_errors() app.formatter.stop() return app.result_count pytest-flake8-1.0.6/README.rst0000644000076500000240000001007013656621347016170 0ustar tholostaff00000000000000pytest plugin for efficiently checking PEP8 compliance ====================================================== .. image:: https://img.shields.io/pypi/v/pytest-flake8.svg :target: https://pypi.python.org/pypi/pytest-flake8 .. image:: https://img.shields.io/pypi/pyversions/pytest-flake8.svg :target: https://pypi.python.org/pypi/pytest-flake8 .. image:: https://img.shields.io/pypi/implementation/pytest-flake8.svg :target: https://pypi.python.org/pypi/pytest-flake8 .. image:: https://img.shields.io/pypi/status/pytest-flake8.svg :target: https://pypi.python.org/pypi/pytest-flake8 .. image:: https://travis-ci.org/tholo/pytest-flake8.svg?branch=master :target: https://travis-ci.org/tholo/pytest-flake8 .. image:: https://img.shields.io/github/issues/tholo/pytest-flake8.svg :target: https://github.com/tholo/pytest-flake8/issues .. image:: https://img.shields.io/github/issues-pr/tholo/pytest-flake8.svg :target: https://github.com/tholo/pytest-flake8/pulls Usage ----- Install by running the command:: pip install pytest-flake8 After installing it, when you run tests with the option:: pytest --flake8 every file ending in ``.py`` will be discovered and checked with flake8. .. note:: If optional flake8 plugins are installed, those will be used automatically. No provisions have been made for configuring these via `pytest`_. .. warning:: Running flake8 tests on your project is likely to cause a number of issues. The plugin allows one to configure on a per-project and per-file basis which errors or warnings to ignore, see flake8-ignore_. .. _flake8-ignore: Configuring FLAKE8 options per project and file ----------------------------------------------- Maximum line length can be configured for the whole project by adding a ``flake8-max-line-length`` option to your ``setup.cfg`` or ``tox.ini`` file like this:: # content of setup.cfg [pytest] flake8-max-line-length = 99 Note that the default will be what naturally comes with `flake8`_ (which it turn gets its default from `pycodestyle`_). You may configure flake8-checking options for your project by adding an ``flake8-ignore`` entry to your ``setup.cfg`` or ``tox.ini`` file like this:: # content of setup.cfg [pytest] flake8-ignore = E201 E231 This would globally prevent complaints about two whitespace issues. Rerunning with the above example will now look better:: $ pytest -q --flake8 collecting ... collected 1 items . 1 passed in 0.01 seconds If you have some files where you want to specifically ignore some errors or warnings you can start a flake8-ignore line with a glob-pattern and a space-separated list of codes:: # content of setup.cfg [pytest] flake8-ignore = *.py E201 doc/conf.py ALL So if you have a conf.py like this:: # content of doc/conf.py func ( [1,2,3]) #this line lots PEP8 errors :) then running again with the previous example will show a single failure and it will ignore doc/conf.py alltogether:: $ pytest --flake8 -v # verbose shows what is ignored ======================================= test session starts ======================================== platform darwin -- Python 2.7.6 -- py-1.4.26 -- pytest-2.7.0 -- /Users/tholo/Source/pytest/bin/python cachedir: /Users/tholo/Source/pytest/src/verify/.cache rootdir: /Users/tholo/Source/angular/src/verify, inifile: setup.cfg plugins: flake8, cache collected 1 items myfile.py PASSED ========================================= 1 passed in 0.00 seconds ========================================= Note that doc/conf.py was not considered or imported. Notes ----- The repository of this plugin is at https://github.com/tholo/pytest-flake8 For more info on `pytest`_ see http://pytest.org The code is partially based on Ronny Pfannschmidt's `pytest-codecheckers`_ plugin. .. _`pytest`: http://pytest.org .. _`flake8`: https://pypi.python.org/pypi/flake8 .. _`pycodestyle`: https://pypi.python.org/pypi/pycodestyle .. _`pytest-codecheckers`: https://pypi.python.org/pypi/pytest-codecheckers