pytest-isort


Namepytest-isort JSON
Version 4.0.0 PyPI version JSON
download
home_pagehttps://github.com/stephrdev/pytest-isort
Summarypy.test plugin to check import ordering using isort
upload_time2024-03-05 08:44:37
maintainer
docs_urlNone
authorStephan Jaekel
requires_python>=3.8,<4
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            py.test plugin to check import ordering using isort
===================================================

.. image:: https://img.shields.io/pypi/v/pytest-isort.svg
   :target: https://pypi.python.org/pypi/pytest-isort
   :alt: Latest Version

.. image:: https://github.com/stephrdev/pytest-isort/workflows/Test/badge.svg?branch=master
   :target: https://github.com/stephrdev/pytest-isort/actions?workflow=Test
   :alt: CI Status


Support
-------

Python 3.7, 3.8, 3.9 and 3.10. pytest>=5.


Usage
-----

install using ``pip``::

    pip install pytest-isort

Activate isort checks when calling ``py.test``::

    py.test --isort

This will execute an isort check against every ``.py`` file (if its not ignored).


Example
-------

Given you have some files with incorrect sorted imports::

    # content of file1.py

    import os
    import sys
    import random

    # content of file2.py

    import json
    import sys
    import os

If you run ``py.test`` and activate the isort plugin you'll se something like this::

    $ py.test --isort
    ========================= test session starts ==========================
    platform darwin -- Python 2.7.9 -- py-1.4.26 -- pytest-2.6.4
    plugins: isort
    collected 2 items

    file1.py F
    file2.py F

    =============================== FAILURES ===============================
    _____________________________ isort-check ______________________________
    ERROR: file1.py Imports are incorrectly sorted.

     import os
    +import random
     import sys
    -import random
    _____________________________ isort-check ______________________________
    ERROR: file2.py Imports are incorrectly sorted.

     import json
    +import os
     import sys
    -import os
    ======================= 2 failed in 0.02 seconds =======================

If you can't change the import ordering for ``file2.py``, you have the option to
exclude ``file2.py`` from isort checks.

Simply add the ``isort_ignore`` setting to your ``py.test`` configuration file::

    [pytest]
    isort_ignore =
        file2.py

Then re-run the tests::

    $ py.test --isort
    ========================= test session starts ==========================
    platform darwin -- Python 2.7.9 -- py-1.4.26 -- pytest-2.6.4
    plugins: isort
    collected 1 items

    file1.py F

    =============================== FAILURES ===============================
    _____________________________ isort-check ______________________________
    ERROR: file1.py Imports are incorrectly sorted.

     import os
    +import random
     import sys
    -import random
    ======================= 1 failed in 0.02 seconds =======================

As you can see, ``file2.py`` is ignored and not checked. Now fix the
import ordering in ``file1.py`` and re-run the tests::

    $ py.test --isort
    ========================= test session starts ==========================
    platform darwin -- Python 2.7.9 -- py-1.4.26 -- pytest-2.6.4
    plugins: isort
    collected 1 items

    file1.py .

    ======================= 1 passed in 0.01 seconds ======================

Everything is properly again. Congratulations!

If you run your testsuite again and again, ``py.test`` will only check changed
files to speed up. You see this by adding ``-rs`` to your ``py.test`` options::

    $ py.test --isort -rs
    ========================= test session starts ==========================
    platform darwin -- Python 2.7.9 -- py-1.4.26 -- pytest-2.6.4
    plugins: isort
    collected 1 items

    file1.py s
    ======================= short test summary info ========================
    SKIP [1] pytest_isort.py:145: file(s) previously passed isort checks

    ====================== 1 skipped in 0.01 seconds ======================


Configuration
-------------

You can exclude files from isort checks by using the ``isort_ignore``
setting in your ``py.test`` configuration file (e.g. ``pytest.ini``)::

    # content of setup.cfg
    [pytest]
    isort_ignore =
        docs/conf.py
        *migrations/*.py

This will ignore the ``conf.py`` python file inside the ``docs`` folder and
also ignore any python file in ``migrations`` folders.

In addition, excluded files in isort's configuration will be ignored too.


Notes
-----

You can use ``isort`` to rewrite your python files and re-order the imports but
this is not part of this plugin.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/stephrdev/pytest-isort",
    "name": "pytest-isort",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4",
    "maintainer_email": "",
    "keywords": "",
    "author": "Stephan Jaekel",
    "author_email": "steph@rdev.info",
    "download_url": "https://files.pythonhosted.org/packages/69/f0/024f4a2ee0b4799a720f352dd7ef9a99077b48bd2c050ff2b08c14feb41d/pytest_isort-4.0.0.tar.gz",
    "platform": null,
    "description": "py.test plugin to check import ordering using isort\n===================================================\n\n.. image:: https://img.shields.io/pypi/v/pytest-isort.svg\n   :target: https://pypi.python.org/pypi/pytest-isort\n   :alt: Latest Version\n\n.. image:: https://github.com/stephrdev/pytest-isort/workflows/Test/badge.svg?branch=master\n   :target: https://github.com/stephrdev/pytest-isort/actions?workflow=Test\n   :alt: CI Status\n\n\nSupport\n-------\n\nPython 3.7, 3.8, 3.9 and 3.10. pytest>=5.\n\n\nUsage\n-----\n\ninstall using ``pip``::\n\n    pip install pytest-isort\n\nActivate isort checks when calling ``py.test``::\n\n    py.test --isort\n\nThis will execute an isort check against every ``.py`` file (if its not ignored).\n\n\nExample\n-------\n\nGiven you have some files with incorrect sorted imports::\n\n    # content of file1.py\n\n    import os\n    import sys\n    import random\n\n    # content of file2.py\n\n    import json\n    import sys\n    import os\n\nIf you run ``py.test`` and activate the isort plugin you'll se something like this::\n\n    $ py.test --isort\n    ========================= test session starts ==========================\n    platform darwin -- Python 2.7.9 -- py-1.4.26 -- pytest-2.6.4\n    plugins: isort\n    collected 2 items\n\n    file1.py F\n    file2.py F\n\n    =============================== FAILURES ===============================\n    _____________________________ isort-check ______________________________\n    ERROR: file1.py Imports are incorrectly sorted.\n\n     import os\n    +import random\n     import sys\n    -import random\n    _____________________________ isort-check ______________________________\n    ERROR: file2.py Imports are incorrectly sorted.\n\n     import json\n    +import os\n     import sys\n    -import os\n    ======================= 2 failed in 0.02 seconds =======================\n\nIf you can't change the import ordering for ``file2.py``, you have the option to\nexclude ``file2.py`` from isort checks.\n\nSimply add the ``isort_ignore`` setting to your ``py.test`` configuration file::\n\n    [pytest]\n    isort_ignore =\n        file2.py\n\nThen re-run the tests::\n\n    $ py.test --isort\n    ========================= test session starts ==========================\n    platform darwin -- Python 2.7.9 -- py-1.4.26 -- pytest-2.6.4\n    plugins: isort\n    collected 1 items\n\n    file1.py F\n\n    =============================== FAILURES ===============================\n    _____________________________ isort-check ______________________________\n    ERROR: file1.py Imports are incorrectly sorted.\n\n     import os\n    +import random\n     import sys\n    -import random\n    ======================= 1 failed in 0.02 seconds =======================\n\nAs you can see, ``file2.py`` is ignored and not checked. Now fix the\nimport ordering in ``file1.py`` and re-run the tests::\n\n    $ py.test --isort\n    ========================= test session starts ==========================\n    platform darwin -- Python 2.7.9 -- py-1.4.26 -- pytest-2.6.4\n    plugins: isort\n    collected 1 items\n\n    file1.py .\n\n    ======================= 1 passed in 0.01 seconds ======================\n\nEverything is properly again. Congratulations!\n\nIf you run your testsuite again and again, ``py.test`` will only check changed\nfiles to speed up. You see this by adding ``-rs`` to your ``py.test`` options::\n\n    $ py.test --isort -rs\n    ========================= test session starts ==========================\n    platform darwin -- Python 2.7.9 -- py-1.4.26 -- pytest-2.6.4\n    plugins: isort\n    collected 1 items\n\n    file1.py s\n    ======================= short test summary info ========================\n    SKIP [1] pytest_isort.py:145: file(s) previously passed isort checks\n\n    ====================== 1 skipped in 0.01 seconds ======================\n\n\nConfiguration\n-------------\n\nYou can exclude files from isort checks by using the ``isort_ignore``\nsetting in your ``py.test`` configuration file (e.g. ``pytest.ini``)::\n\n    # content of setup.cfg\n    [pytest]\n    isort_ignore =\n        docs/conf.py\n        *migrations/*.py\n\nThis will ignore the ``conf.py`` python file inside the ``docs`` folder and\nalso ignore any python file in ``migrations`` folders.\n\nIn addition, excluded files in isort's configuration will be ignored too.\n\n\nNotes\n-----\n\nYou can use ``isort`` to rewrite your python files and re-order the imports but\nthis is not part of this plugin.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "py.test plugin to check import ordering using isort",
    "version": "4.0.0",
    "project_urls": {
        "Homepage": "https://github.com/stephrdev/pytest-isort",
        "Repository": "https://github.com/stephrdev/pytest-isort"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f1a6848a7bdec751e5648e7200c0e5339398eb9607666d83848840c8c1553a80",
                "md5": "ad6d22c21c26359ae0d1d4a6859f5481",
                "sha256": "14bb3281bab587d6beb53129481e8885232249ec5cfeaf5d903a561ff0589620"
            },
            "downloads": -1,
            "filename": "pytest_isort-4.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ad6d22c21c26359ae0d1d4a6859f5481",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4",
            "size": 6899,
            "upload_time": "2024-03-05T08:44:36",
            "upload_time_iso_8601": "2024-03-05T08:44:36.281276Z",
            "url": "https://files.pythonhosted.org/packages/f1/a6/848a7bdec751e5648e7200c0e5339398eb9607666d83848840c8c1553a80/pytest_isort-4.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "69f0024f4a2ee0b4799a720f352dd7ef9a99077b48bd2c050ff2b08c14feb41d",
                "md5": "c2b49b086976c98194b8d4da3bc01ce1",
                "sha256": "00e99642e282b00b849cf9b49d9102a02ab8c4ec549ace57d7868b723713aaa9"
            },
            "downloads": -1,
            "filename": "pytest_isort-4.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c2b49b086976c98194b8d4da3bc01ce1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4",
            "size": 5597,
            "upload_time": "2024-03-05T08:44:37",
            "upload_time_iso_8601": "2024-03-05T08:44:37.443476Z",
            "url": "https://files.pythonhosted.org/packages/69/f0/024f4a2ee0b4799a720f352dd7ef9a99077b48bd2c050ff2b08c14feb41d/pytest_isort-4.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-05 08:44:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "stephrdev",
    "github_project": "pytest-isort",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pytest-isort"
}
        
Elapsed time: 0.22170s