pytest-pep8


Namepytest-pep8 JSON
Version 1.0.6 PyPI version JSON
download
home_pagehttps://bitbucket.org/pytest-dev/pytest-pep8
Summarypytest plugin to check PEP8 requirements
upload_time2014-04-27 06:21:28
maintainerNone
docs_urlNone
authorHolger Krekel and Ronny Pfannschmidt
requires_pythonNone
licenseMIT license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: https://drone.io/bitbucket.org/pytest-dev/pytest-pep8/status.png
   :target: https://drone.io/bitbucket.org/pytest-dev/pytest-pep8/latest
.. image:: https://pypip.in/v/pytest-pep8/badge.png
   :target: https://pypi.python.org/pypi/pytest-pep8

py.test plugin for efficiently checking PEP8 compliance 
=======================================================

Usage
-----

install via::

    pip install pytest-pep8

if you then type::

    py.test --pep8
    
every file ending in ``.py`` will be discovered and pep8-checked, 
starting from the command line arguments. 

.. warning::

    Running pep8 tests on your project is likely to cause a lot of 
    issues.  This plugin allows to configure on a per-project and
    per-file basis which errors or warnings to care about, see
    pep8ignore_.  As a preliminary advise, if you have 
    projects where you don't want to care at all about pep8 checks, 
    you can put configure it like this::

        # content of setup.cfg (or pytest.ini)
        [pytest]
        pep8ignore = * ALL


A little example 
----------------

If you have a pep8-violating file like this::

    # content of myfile.py
 
    somefunc( 123,456)

you can run it with the plugin installed::

    $ py.test --pep8
    =========================== test session starts ============================
    platform linux2 -- Python 2.7.6 -- py-1.4.30 -- pytest-2.7.2
    rootdir: /tmp/doc-exec-2, inifile: 
    plugins: pep8, cache
    collected 1 items
    
    myfile.py F
    
    ================================= FAILURES =================================
    ________________________________ PEP8-check ________________________________
    /tmp/doc-exec-2/myfile.py:2:10: E201 whitespace after '('
    somefunc( 123,456)
             ^
    /tmp/doc-exec-2/myfile.py:2:14: E231 missing whitespace after ','
    somefunc( 123,456)
                 ^
    
    ========================= 1 failed in 0.00 seconds =========================

For the meaning of (E)rror and (W)arning codes, see the error
output when running against your files or checkout `pep8.py
<https://github.com/jcrocholl/pep8/blob/master/pep8.py>`_.

Let's not now fix the PEP8 errors::

    # content of myfile.py
    somefunc(123, 456)

and run again::

    $ py.test --pep8
    =========================== test session starts ============================
    platform linux2 -- Python 2.7.6 -- py-1.4.30 -- pytest-2.7.2
    rootdir: /tmp/doc-exec-2, inifile: 
    plugins: pep8, cache
    collected 1 items
    
    myfile.py .
    
    ========================= 1 passed in 0.00 seconds =========================

the pep8 check now is passing. Moreover, if
you run it once again (and report skip reasons)::

    $ py.test --pep8 -rs 
    =========================== test session starts ============================
    platform linux2 -- Python 2.7.6 -- py-1.4.30 -- pytest-2.7.2
    rootdir: /tmp/doc-exec-2, inifile: 
    plugins: pep8, cache
    collected 1 items
    
    myfile.py s
    ========================= short test summary info ==========================
    SKIP [1] /home/hpk/p/pytest-pep8/pytest_pep8.py:65: file(s) previously passed PEP8 checks
    
    ======================== 1 skipped in 0.00 seconds =========================

you can see that the pep8 check was skipped because
the file has not been modified since it was last checked.
As the pep8 plugin uses the 
`pytest-cache plugin <http://pypi.python.org/pypi/pytest-cache>`_
to implement its caching, you can use its ``--clearcache`` option to 
remove all pytest caches, among them the pep8 related one, which 
will trigger the pep8 checking code to run once again::

    $ py.test --pep8 --clearcache
    =========================== test session starts ============================
    platform linux2 -- Python 2.7.6 -- py-1.4.30 -- pytest-2.7.2
    rootdir: /tmp/doc-exec-2, inifile: 
    plugins: pep8, cache
    collected 1 items
    
    myfile.py .
    
    ========================= 1 passed in 0.00 seconds =========================

.. _pep8ignore:

Configuring PEP8 options per project and file
---------------------------------------------

You may configure PEP8-checking options for your project
by adding an ``pep8ignore`` entry to your ``setup.cfg``
or ``setup.cfg`` file like this::

    # content of setup.cfg
    [pytest]
    pep8ignore = E201 E231

This would globally prevent complaints about two whitespace issues.
Rerunning with the above example will now look better::

    $ py.test -q  --pep8
    .
    1 passed in 0.00 seconds

If you have some files where you want to specifically ignore 
some errors or warnings you can start a pep8ignore line with 
a glob-pattern and a space-separated list of codes::

    # content of setup.cfg
    [pytest]
    pep8ignore = 
        *.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::

    $ py.test --pep8 -v # verbose shows what is ignored
    =========================== test session starts ============================
    platform linux2 -- Python 2.7.6 -- py-1.4.30 -- pytest-2.7.2 -- /home/hpk/venv/clean/bin/python
    cachedir: /tmp/doc-exec-2/.cache
    rootdir: /tmp/doc-exec-2, inifile: setup.cfg
    plugins: pep8, cache
    collecting ... collected 1 items
    
    myfile.py PASSED
    
    ========================= 1 passed in 0.01 seconds =========================

Note that doc/conf.py was not considered or imported.

If you'ld like to have longer lines than 79 chars (which is the default for the
pep8 checker), you can configure it like this::

    # content of setup.cfg
    [pytest]
    pep8maxlinelength = 99

Running PEP8 checks and no other tests
--------------------------------------

You can also restrict your test run to only perform "pep8" tests
and not any other tests by typing::

    py.test --pep8 -m pep8

This will only run test items with the "pep8" marker which this
plugins adds dynamically.

Notes
-----

The repository of this plugin is at http://bitbucket.org/pytest-dev/pytest-pep8

For more info on py.test see http://pytest.org

The code is partially based on Ronny Pfannschmidt's pytest-codecheckers plugin.
            

Raw data

            {
    "_id": null,
    "home_page": "https://bitbucket.org/pytest-dev/pytest-pep8",
    "name": "pytest-pep8",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": null,
    "author": "Holger Krekel and Ronny Pfannschmidt",
    "author_email": "holger.krekel@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/1f/1c/c834344ef39381558b047bea1e3005197fa8457c199d58219996ca07defb/pytest-pep8-1.0.6.tar.gz",
    "platform": "UNKNOWN",
    "description": ".. image:: https://drone.io/bitbucket.org/pytest-dev/pytest-pep8/status.png\r\n   :target: https://drone.io/bitbucket.org/pytest-dev/pytest-pep8/latest\r\n.. image:: https://pypip.in/v/pytest-pep8/badge.png\r\n   :target: https://pypi.python.org/pypi/pytest-pep8\r\n\r\npy.test plugin for efficiently checking PEP8 compliance \r\n=======================================================\r\n\r\nUsage\r\n-----\r\n\r\ninstall via::\r\n\r\n    pip install pytest-pep8\r\n\r\nif you then type::\r\n\r\n    py.test --pep8\r\n    \r\nevery file ending in ``.py`` will be discovered and pep8-checked, \r\nstarting from the command line arguments. \r\n\r\n.. warning::\r\n\r\n    Running pep8 tests on your project is likely to cause a lot of \r\n    issues.  This plugin allows to configure on a per-project and\r\n    per-file basis which errors or warnings to care about, see\r\n    pep8ignore_.  As a preliminary advise, if you have \r\n    projects where you don't want to care at all about pep8 checks, \r\n    you can put configure it like this::\r\n\r\n        # content of setup.cfg (or pytest.ini)\r\n        [pytest]\r\n        pep8ignore = * ALL\r\n\r\n\r\nA little example \r\n----------------\r\n\r\nIf you have a pep8-violating file like this::\r\n\r\n    # content of myfile.py\r\n \r\n    somefunc( 123,456)\r\n\r\nyou can run it with the plugin installed::\r\n\r\n    $ py.test --pep8\r\n    =========================== test session starts ============================\n    platform linux2 -- Python 2.7.6 -- py-1.4.30 -- pytest-2.7.2\n    rootdir: /tmp/doc-exec-2, inifile: \n    plugins: pep8, cache\n    collected 1 items\n    \n    myfile.py F\n    \n    ================================= FAILURES =================================\n    ________________________________ PEP8-check ________________________________\n    /tmp/doc-exec-2/myfile.py:2:10: E201 whitespace after '('\n    somefunc( 123,456)\n             ^\n    /tmp/doc-exec-2/myfile.py:2:14: E231 missing whitespace after ','\n    somefunc( 123,456)\n                 ^\n    \n    ========================= 1 failed in 0.00 seconds =========================\n\r\nFor the meaning of (E)rror and (W)arning codes, see the error\r\noutput when running against your files or checkout `pep8.py\r\n<https://github.com/jcrocholl/pep8/blob/master/pep8.py>`_.\r\n\r\nLet's not now fix the PEP8 errors::\r\n\r\n    # content of myfile.py\r\n    somefunc(123, 456)\r\n\r\nand run again::\r\n\r\n    $ py.test --pep8\r\n    =========================== test session starts ============================\n    platform linux2 -- Python 2.7.6 -- py-1.4.30 -- pytest-2.7.2\n    rootdir: /tmp/doc-exec-2, inifile: \n    plugins: pep8, cache\n    collected 1 items\n    \n    myfile.py .\n    \n    ========================= 1 passed in 0.00 seconds =========================\n\r\nthe pep8 check now is passing. Moreover, if\r\nyou run it once again (and report skip reasons)::\r\n\r\n    $ py.test --pep8 -rs \r\n    =========================== test session starts ============================\n    platform linux2 -- Python 2.7.6 -- py-1.4.30 -- pytest-2.7.2\n    rootdir: /tmp/doc-exec-2, inifile: \n    plugins: pep8, cache\n    collected 1 items\n    \n    myfile.py s\n    ========================= short test summary info ==========================\n    SKIP [1] /home/hpk/p/pytest-pep8/pytest_pep8.py:65: file(s) previously passed PEP8 checks\n    \n    ======================== 1 skipped in 0.00 seconds =========================\n\r\nyou can see that the pep8 check was skipped because\r\nthe file has not been modified since it was last checked.\r\nAs the pep8 plugin uses the \r\n`pytest-cache plugin <http://pypi.python.org/pypi/pytest-cache>`_\r\nto implement its caching, you can use its ``--clearcache`` option to \r\nremove all pytest caches, among them the pep8 related one, which \r\nwill trigger the pep8 checking code to run once again::\r\n\r\n    $ py.test --pep8 --clearcache\r\n    =========================== test session starts ============================\n    platform linux2 -- Python 2.7.6 -- py-1.4.30 -- pytest-2.7.2\n    rootdir: /tmp/doc-exec-2, inifile: \n    plugins: pep8, cache\n    collected 1 items\n    \n    myfile.py .\n    \n    ========================= 1 passed in 0.00 seconds =========================\n\r\n.. _pep8ignore:\r\n\r\nConfiguring PEP8 options per project and file\r\n---------------------------------------------\r\n\r\nYou may configure PEP8-checking options for your project\r\nby adding an ``pep8ignore`` entry to your ``setup.cfg``\r\nor ``setup.cfg`` file like this::\r\n\r\n    # content of setup.cfg\r\n    [pytest]\r\n    pep8ignore = E201 E231\r\n\r\nThis would globally prevent complaints about two whitespace issues.\r\nRerunning with the above example will now look better::\r\n\r\n    $ py.test -q  --pep8\r\n    .\n    1 passed in 0.00 seconds\n\r\nIf you have some files where you want to specifically ignore \r\nsome errors or warnings you can start a pep8ignore line with \r\na glob-pattern and a space-separated list of codes::\r\n\r\n    # content of setup.cfg\r\n    [pytest]\r\n    pep8ignore = \r\n        *.py E201\r\n        doc/conf.py ALL\r\n\r\nSo if you have a conf.py like this::\r\n\r\n    # content of doc/conf.py\r\n\r\n    func (  [1,2,3]) #this line lots pep8 errors :)\r\n\r\nthen running again with the previous example will show a single\r\nfailure and it will ignore doc/conf.py alltogether::\r\n\r\n    $ py.test --pep8 -v # verbose shows what is ignored\r\n    =========================== test session starts ============================\n    platform linux2 -- Python 2.7.6 -- py-1.4.30 -- pytest-2.7.2 -- /home/hpk/venv/clean/bin/python\n    cachedir: /tmp/doc-exec-2/.cache\n    rootdir: /tmp/doc-exec-2, inifile: setup.cfg\n    plugins: pep8, cache\n    collecting ... collected 1 items\n    \n    myfile.py PASSED\n    \n    ========================= 1 passed in 0.01 seconds =========================\n\r\nNote that doc/conf.py was not considered or imported.\r\n\r\nIf you'ld like to have longer lines than 79 chars (which is the default for the\r\npep8 checker), you can configure it like this::\r\n\r\n    # content of setup.cfg\r\n    [pytest]\r\n    pep8maxlinelength = 99\r\n\r\nRunning PEP8 checks and no other tests\r\n--------------------------------------\r\n\r\nYou can also restrict your test run to only perform \"pep8\" tests\r\nand not any other tests by typing::\r\n\r\n    py.test --pep8 -m pep8\r\n\r\nThis will only run test items with the \"pep8\" marker which this\r\nplugins adds dynamically.\r\n\r\nNotes\r\n-----\r\n\r\nThe repository of this plugin is at http://bitbucket.org/pytest-dev/pytest-pep8\r\n\r\nFor more info on py.test see http://pytest.org\r\n\r\nThe code is partially based on Ronny Pfannschmidt's pytest-codecheckers plugin.",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "pytest plugin to check PEP8 requirements",
    "version": "1.0.6",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "3debd0bac8f63532ae70c7351e73e993",
                "sha256": "032ef7e5fa3ac30f4458c73e05bb67b0f036a8a5cb418a534b3170f89f120318"
            },
            "downloads": -1,
            "filename": "pytest-pep8-1.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "3debd0bac8f63532ae70c7351e73e993",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7271,
            "upload_time": "2014-04-27T06:21:28",
            "upload_time_iso_8601": "2014-04-27T06:21:28.945626Z",
            "url": "https://files.pythonhosted.org/packages/1f/1c/c834344ef39381558b047bea1e3005197fa8457c199d58219996ca07defb/pytest-pep8-1.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2014-04-27 06:21:28",
    "github": false,
    "gitlab": false,
    "bitbucket": true,
    "bitbucket_user": "pytest-dev",
    "bitbucket_project": "pytest-pep8",
    "lcname": "pytest-pep8"
}
        
Elapsed time: 0.02208s