GithubHelp home page GithubHelp logo

pytest-flake8's Introduction

pytest plugin for efficiently checking PEP8 compliance

https://travis-ci.org/tholo/pytest-flake8.svg?branch=master

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.

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-flake8's People

Contributors

alex-dr avatar andras-tim avatar artiemq avatar brianbruggeman avatar jezdez avatar ktdreyer avatar mforbes avatar neongraal avatar tholo avatar wrwrwr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.