{"id":10143,"library":"pytest-isort","title":"pytest-isort","description":"pytest-isort is a pytest plugin that integrates isort's import ordering and formatting checks directly into the pytest test suite. It ensures that all Python files discoverable by pytest adhere to isort's configured rules, failing the test run if any incorrectly sorted imports are found. The current version is 4.0.0, released in February 2024, with active maintenance and updates to support newer Python and pytest versions.","status":"active","version":"4.0.0","language":"en","source_language":"en","source_url":"https://github.com/stephrdev/pytest-isort","tags":["pytest","isort","linting","imports","testing","code quality"],"install":[{"cmd":"pip install pytest-isort","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for pytest plugin functionality.","package":"pytest","optional":false},{"reason":"Provides the core import sorting logic.","package":"isort","optional":false}],"imports":[],"quickstart":{"code":"import os\n\n# test_imports.py\n\nimport os\nimport sys\nfrom collections import defaultdict\n\ndef test_correct_imports():\n    # This test will pass isort checks if imports are sorted correctly\n    assert True\n\ndef test_bad_imports():\n    # This test (or file content) will cause pytest-isort to fail\n    # if imports are not sorted.\n    x = 1 # Added to avoid 'Empty file' issue with isort check itself\n    assert True\n\n# To run this, save it as `test_imports.py` and run `pytest` in the same directory.\n# If the imports within the file are not sorted according to isort rules,\n# pytest-isort will report a failure.","lang":"python","description":"To quickly use `pytest-isort`, simply install it and run `pytest`. The plugin automatically discovers and checks Python files collected by pytest for correct import ordering based on your project's `isort` configuration. If any files have unsorted imports, `pytest` will report a failure."},"warnings":[{"fix":"Upgrade Python to 3.8+, pytest to 7+, and isort to 5.x or newer. Example: `pip install -U pytest isort`","message":"Version 4.0.0 drops support for older Python and pytest versions. Python 3.8+ and pytest 7+ are now required. It also explicitly requires isort 5.x or newer.","severity":"breaking","affected_versions":"<4.0.0"},{"fix":"Ensure your `isort` configuration is correctly defined and understood. To apply fixes based on your configuration, run `isort .` in your project root.","message":"`pytest-isort` respects your project's `isort` configuration (e.g., `pyproject.toml`, `.isort.cfg`, `.editorconfig`). If your `isort` configuration differs from default expectations, `pytest-isort` will follow your configuration, potentially leading to unexpected pass/fail results.","severity":"gotcha","affected_versions":"All"},{"fix":"For comprehensive project-wide import checking, consider integrating `isort --check-only --profile black .` into your pre-commit hooks or CI/CD pipeline, independent of `pytest-isort`.","message":"`pytest-isort` only checks files that are discovered and collected by `pytest` as part of its test run. It does not automatically check all Python files in your project (e.g., application code not under a `test_` prefix or configured for collection).","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Upgrade `pytest` to version 7 or newer: `pip install -U pytest`","cause":"Your installed `pytest` version is too old for `pytest-isort` v4.0.0.","error":"_pytest.runner.Skipped: pytest-isort requires pytest >= 7."},{"fix":"Install `isort`: `pip install isort`","cause":"The `isort` library, a core dependency, is not installed or not available in your Python environment.","error":"ModuleNotFoundError: No module named 'isort'"},{"fix":"Manually sort the imports or run `isort .` (or `isort --profile black .` if using black) in your project root to automatically fix all files.","cause":"One or more Python files being checked by `pytest-isort` have imports that do not conform to your project's `isort` configuration.","error":"Imports are incorrectly sorted and/or formatted. Please run `isort` to fix this."},{"fix":"Ensure `isort` is upgraded to version 5.x or newer: `pip install -U isort`","cause":"This can sometimes occur if `isort` is installed but an older, incompatible version (e.g., < 5.0) is present, leading to internal errors when `pytest-isort` tries to use it.","error":"E TypeError: argument of type 'NoneType' is not iterable"}]}