pytest-black
A pytest plugin to enable format checking with black
What it is and what it does
pytest-black is a pytest plugin that integrates black's code formatting checks into your test suite. When you run pytest with the --black flag, it scans your code and reports any formatting violations that black would fix, displaying a diff of suggested changes. The plugin does not modify your code—it only reports violations, leaving the decision to apply changes to you or your CI pipeline.
The plugin relies on pytest, black, and toml as runtime dependencies. It reads black configuration from pyproject.toml if present, allowing you to customize formatting rules per project. This makes it useful for enforcing consistent code style as part of automated testing rather than as a standalone formatter.
Use it for:
- Enforce code formatting standards in CI/CD pipelines by failing tests when black violations are detected.
- Catch formatting inconsistencies during local development before pushing code to version control.
- Integrate style checking into existing pytest workflows without adding separate linting steps.
- Report formatting diffs to developers during test runs so they can see exactly what black would change.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that runs black format checks on your code during test execution, reporting formatting violations without applying changes automatically.
Yes, if you already use pytest and black and want formatting checks as part of your test suite. The low install friction and permissive license make it straightforward to add. However, the dormant maintenance status (last commit 2024-12-23, zero repository stars) and old Python support floor (>=3.5) suggest limited ongoing development; verify compatibility with your current black version before relying on it in production CI/CD.
Install
pytest-black on PyPI
pip
pip install pytest-blackuv
uv add pytest-blackpoetry
poetry add pytest-blackInstalling pytest-black
Before you install
Low friction install with three straightforward dependencies (pytest, black, toml). Maintenance is dormant—last release was 2024-12-15 but no commits since 2024-12-23, and the repository shows zero stars, suggesting limited active community engagement.
License in practice
MIT license (permissive) means you can use, modify, and distribute the package freely with minimal restrictions, typical for open-source development tools.
Quickstart
pip install pytest-black
# In your test run:
pytest --black
# Outputs formatting diffs without applying changes
Requires black 19.3b0 or later; requires pytest and toml as runtime dependencies.
Verify before relying
- Whether the plugin works correctly with recent black versions beyond 19.3b0.
- Current state of compatibility with modern Python 3.x versions (requires_python is >=3.5, which is quite old).
- Whether dormant maintenance status affects reliability in active CI/CD pipelines.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.5) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — pytest, black, toml |
| Maintenance | dormant — 607 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 157,185/month — #10,762 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_black-0.6.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
flake8-blackA flake8 plugin that runs black's code style…
permissive · top 15,000 on PyPI
pytest-enablerA pytest plugin that conditionally enables…
permissive · top 15,000 on PyPI
pytest-ruffA pytest plugin that integrates ruff code…
unclear · top 15,000 on PyPI
pytest-qtpytest-qt is a pytest plugin that provides…
permissive · top 5,000 on PyPI
jupyter-blackA Jupyter Notebook and JupyterLab extension…
permissive · top 15,000 on PyPI
darkerDarker reformats Python source code in Git…
permissive · top 15,000 on PyPI
pytest-antilruClears functools.lru_cache between pytest test…
permissive · top 15,000 on PyPI
blackBlack reformats Python source code to a…
permissive · top 1,000 on PyPI
tox-ansibleA tox plugin that orchestrates testing of…
permissive · top 15,000 on PyPI
pytest-pspecFormats pytest test output in RSpec-style…
permissive · top 15,000 on PyPI