pytest-isort
py.test plugin to check import ordering using isort
What it is and what it does
pytest-isort is a pytest plugin that integrates isort import-sorting checks into your test suite. When you run pytest with the --isort flag, it scans all Python files in your project and fails tests for any files with incorrectly ordered imports, showing a diff of what isort expects. You can exclude specific files or patterns via isort_ignore in your pytest configuration, and the plugin skips re-checking files that previously passed to speed up repeated test runs.
The plugin sits between pytest and isort, using isort as its sorting engine. It's useful for teams that want import-order enforcement as part of their CI/CD pipeline without requiring a separate linting step. Configuration is minimal—just add the --isort flag or set isort_ignore rules in pytest.ini—and it respects isort's own configuration files.
Use it for:
- Enforce consistent import ordering in CI/CD pipelines by failing builds when imports are unsorted.
- Catch import-order violations during local test runs before code review, using pytest's existing test infrastructure.
- Exclude specific files or migration directories from import checks while validating the rest of the codebase.
- Speed up repeated test runs by skipping files that already passed isort checks in previous runs.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that automatically checks whether imports in Python files are sorted correctly according to isort rules, failing tests when import order violations are found.
Yes, if you use pytest and want import-order enforcement as part of your test suite. The plugin is stable, has no known vulnerabilities, and integrates cleanly with isort. Maintenance is dormant but the package is mature and unlikely to need updates for basic functionality. Install it if your team values consistent import ordering; skip it if you prefer a separate linting tool or have no import-order standards.
Install
pytest-isort on PyPI
pip
pip install pytest-isortuv
uv add pytest-isortpoetry
poetry add pytest-isortInstalling pytest-isort
Before you install
Low friction install with two straightforward runtime dependencies (pytest and isort). Maintenance is dormant—last release was 2024-03-05 and no commits since 2024-04-12—but the package is marked Production/Stable and carries no known vulnerabilities.
License in practice
MIT license (permissive) places no restrictions on use, modification, or distribution in proprietary or open-source projects.
Quickstart
pip install pytest-isort
# Then in your test run:
py.test --isort
# Or configure in pytest.ini:
[pytest]
isort_ignore =
docs/conf.py
Requires Python >=3.8,<4 and pytest>=5 as runtime dependencies.
Verify before relying
- Whether the plugin's skip-on-unchanged-files optimization (mentioned in the description) remains reliable across pytest versions.
- Current compatibility with isort's latest major versions and any breaking changes to isort's API.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8,<4) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — pytest, isort |
| Maintenance | dormant — 892 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 101,768/month — #12,917 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_isort-4.0.0-py3-none-any.whl
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
isortisort sorts Python imports alphabetically and…
permissive · top 1,000 on PyPI
pytest-timestamperA pytest plugin that prefixes each test output…
unclear · top 15,000 on PyPI
pytest-pep8A pytest plugin that integrates PEP8 style…
permissive · top 15,000 on PyPI
flake8-isortIntegrates isort into flake8 linting, reporting…
copyleft · top 5,000 on PyPI
pytest-pickedA pytest plugin that automatically runs only…
permissive · top 5,000 on PyPI
pytest-orderingA pytest plugin that lets you control the…
permissive · top 5,000 on PyPI
usortμsort sorts Python imports within detected…
permissive · top 5,000 on PyPI
pytest-mypy-pluginsA pytest plugin that runs type-checking tests…
permissive · top 15,000 on PyPI
pytest-randomlyA pytest plugin that randomly shuffles test…
permissive · top 5,000 on PyPI
pytest-onlyA pytest plugin that runs only tests marked…
permissive · top 15,000 on PyPI