././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1647641586.7199557 pytest-flake8-1.1.1/0000755000076500000240000000000014215201763013263 5ustar00tholostaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1647639211.0 pytest-flake8-1.1.1/CHANGELOG0000644000076500000240000000455214215175253014507 0ustar00tholostaff1.1.1 ----- - Update classifiers to indicate older versions are no longer supported - No longer use deprecated pytest constructs - Bump requirements to more accurately indicate what is currently needed 1.1.0 ----- - Drop Python 2 support and dependency on py; from @erikkemperman - Drop support for Python 3.5, 3.6 - Stop testing on Python versions prior to 3.7 - Add a `flake8-max-doc-length` option; from @rodrigomologni - Fix some minor typos; from @kianmeng 1.0.7 ----- - Implement collect() for Flake8Item; from @thomascobb - Document skipping behavior in README; from @jpyams 1.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 string 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 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1427823698.0 pytest-flake8-1.1.1/LICENSE0000644000076500000240000000235212506556122014275 0ustar00tholostaffCopyright (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. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1427827954.0 pytest-flake8-1.1.1/MANIFEST.in0000644000076500000240000000021412506566362015030 0ustar00tholostaffinclude CHANGELOG include README.rst include setup.py include tox.ini include LICENSE include test_flake8.py graft doc graft test_flake8.py ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1647641586.7200058 pytest-flake8-1.1.1/PKG-INFO0000644000076500000240000001271414215201763014365 0ustar00tholostaffMetadata-Version: 2.1 Name: pytest-flake8 Version: 1.1.1 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 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 :: 3 Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 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 License-File: LICENSE 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 and maximum doc line length can be configured for the whole project by adding a ``flake8-max-line-length`` option and ``flake8-max-doc-length`` to your ``setup.cfg`` or ``tox.ini`` file like this:: # content of setup.cfg [tool:pytest] flake8-max-line-length = 99 flake8-max-doc-length = 74 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 [tool: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 [tool: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 altogether:: $ 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. FAQs ----- All the flake8 tests are skipping! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This is by design. Clean flake8 results are cached and, unless the file is modified, not tested again. You can run with ``pytest --cache-clear --flake8`` to override this. 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 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1646460091.0 pytest-flake8-1.1.1/README.rst0000644000076500000240000001064114210576273014762 0ustar00tholostaffpytest 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 and maximum doc line length can be configured for the whole project by adding a ``flake8-max-line-length`` option and ``flake8-max-doc-length`` to your ``setup.cfg`` or ``tox.ini`` file like this:: # content of setup.cfg [tool:pytest] flake8-max-line-length = 99 flake8-max-doc-length = 74 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 [tool: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 [tool: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 altogether:: $ 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. FAQs ----- All the flake8 tests are skipping! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This is by design. Clean flake8 results are cached and, unless the file is modified, not tested again. You can run with ``pytest --cache-clear --flake8`` to override this. 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1647641586.7198565 pytest-flake8-1.1.1/pytest_flake8.egg-info/0000755000076500000240000000000014215201763017537 5ustar00tholostaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1647641586.0 pytest-flake8-1.1.1/pytest_flake8.egg-info/PKG-INFO0000644000076500000240000001271414215201762020640 0ustar00tholostaffMetadata-Version: 2.1 Name: pytest-flake8 Version: 1.1.1 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 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 :: 3 Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 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 License-File: LICENSE 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 and maximum doc line length can be configured for the whole project by adding a ``flake8-max-line-length`` option and ``flake8-max-doc-length`` to your ``setup.cfg`` or ``tox.ini`` file like this:: # content of setup.cfg [tool:pytest] flake8-max-line-length = 99 flake8-max-doc-length = 74 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 [tool: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 [tool: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 altogether:: $ 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. FAQs ----- All the flake8 tests are skipping! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This is by design. Clean flake8 results are cached and, unless the file is modified, not tested again. You can run with ``pytest --cache-clear --flake8`` to override this. 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 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1647641586.0 pytest-flake8-1.1.1/pytest_flake8.egg-info/SOURCES.txt0000644000076500000240000000050314215201762021420 0ustar00tholostaffCHANGELOG 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.txt././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1647641586.0 pytest-flake8-1.1.1/pytest_flake8.egg-info/dependency_links.txt0000644000076500000240000000000114215201762023604 0ustar00tholostaff ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1647641586.0 pytest-flake8-1.1.1/pytest_flake8.egg-info/entry_points.txt0000644000076500000240000000004214215201762023030 0ustar00tholostaff[pytest11] flake8 = pytest_flake8 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1647641586.0 pytest-flake8-1.1.1/pytest_flake8.egg-info/requires.txt0000644000076500000240000000003014215201762022127 0ustar00tholostaffflake8>=4.0 pytest>=7.0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1647641586.0 pytest-flake8-1.1.1/pytest_flake8.egg-info/top_level.txt0000644000076500000240000000001614215201762022265 0ustar00tholostaffpytest_flake8 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1647641440.0 pytest-flake8-1.1.1/pytest_flake8.py0000644000076500000240000002013214215201540016406 0ustar00tholostaff"""py.test plugin to test with flake8.""" import os import re from contextlib import redirect_stdout, redirect_stderr from io import BytesIO, TextIOWrapper from flake8.main import application from flake8.options import config import pytest __version__ = '1.1.1' 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-doc-length", help="maximum doc 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._flake8maxdoclen = config.getini("flake8-max-doc-length") config._flake8maxcomplexity = config.getini("flake8-max-complexity") config._flake8showsource = 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(file_path, path, parent): """Filter files down to which ones should be checked.""" config = parent.config if config.option.flake8 and file_path.suffix in config._flake8exts: flake8ignore = config._flake8ignore(path) if flake8ignore is not None: item = Flake8File.from_parent( parent, path=file_path, flake8ignore=flake8ignore, maxlength=config._flake8maxlen, maxdoclength=config._flake8maxdoclen, maxcomplexity=config._flake8maxcomplexity, showsource=config._flake8showsource, statistics=config._flake8statistics) return item 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 Flake8File(pytest.File): def __init__(self, *k, flake8ignore=None, maxlength=None, maxdoclength=None, maxcomplexity=None, showsource=None, statistics=None, **kw): super().__init__(*k, **kw) self.flake8ignore = flake8ignore self.maxlength = maxlength self.maxdoclength = maxdoclength self.maxcomplexity = maxcomplexity self.showsource = showsource self.statistics = statistics def collect(self): return [Flake8Item.from_parent(self, name="flake-8")] class Flake8Item(pytest.Item): def __init__(self, *k, **kwargs): super().__init__(*k, **kwargs) self._nodeid += "::FLAKE8" self.add_marker("flake8") self.flake8ignore = self.parent.flake8ignore self.maxlength = self.parent.maxlength self.maxdoclength = self.parent.maxdoclength self.maxcomplexity = self.parent.maxcomplexity self.showsource = self.parent.showsource self.statistics = self.parent.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): with BytesIO() as bo, TextIOWrapper(bo, encoding='utf-8') as to, \ BytesIO() as be, TextIOWrapper(be, encoding='utf-8') as te, \ redirect_stdout(to), redirect_stderr(te): found_errors = check_file( self.fspath, self.flake8ignore, self.maxlength, self.maxdoclength, self.maxcomplexity, self.showsource, self.statistics ) to.flush() te.flush() out = bo.getvalue().decode('utf-8') err = be.getvalue().decode('utf-8') 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, maxdoclenght, maxcomplexity, showsource, statistics): """Run flake8 over a single file, and return the number of failures.""" args = [] if maxlength: args += ['--max-line-length', maxlength] if maxdoclenght: args += ['--max-doc-length', maxdoclenght] if maxcomplexity: args += ['--max-complexity', maxcomplexity] if showsource: args += ['--show-source'] if statistics: args += ['--statistics'] app = application.Application() 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) if flake8ignore: app.options.ignore = flake8ignore app.make_formatter() # fix this 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 ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1647641586.7202322 pytest-flake8-1.1.1/setup.cfg0000644000076500000240000000016614215201763015107 0ustar00tholostaff[bdist_wheel] universal = true [devpi:upload] formats = bdist_wheel,sdist.tgz [egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1647639403.0 pytest-flake8-1.1.1/setup.py0000644000076500000240000000255314215175553015011 0ustar00tholostaff# -*- coding: utf-8 -*- """Install package.""" from setuptools import setup setup( name='pytest-flake8', version='1.1.1', 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 :: 3", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "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>=4.0', 'pytest>=7.0', ], ) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1608157623.0 pytest-flake8-1.1.1/test_flake8.py0000644000076500000240000001241613766504667016075 0ustar00tholostaff# 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) def test_run_on_init_file(testdir): d = testdir.mkpydir("tests") result = testdir.runpytest("--flake8", d / "__init__.py") result.assert_outcomes(passed=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 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1646460052.0 pytest-flake8-1.1.1/tox.ini0000644000076500000240000000066014210576224014602 0ustar00tholostaff[tox] envlist=py310-pytesttrunk,py310-xdist,py37,py38,py39,py310,pypy3 [testenv] deps=pytest commands= pytest --junitxml={envlogdir}/junit-{envname}.xml {posargs} [testenv:py310-pytesttrunk] pip_pre=true deps=pytest [testenv:py310-xdist] deps={[testenv]deps} pytest-xdist commands= pytest -n3 --junitxml={envlogdir}/junit-{envname}.xml {posargs} [pytest] addopts=--flake8 junit_family=xunit1 [flake8] ignore=E128