Registry / testing / pytest-black

pytest-black

JSON →
library0.6.0pypypiunverified

pytest-black is a pytest plugin that enables code format checking using the 'black' formatter directly within the pytest test suite. It integrates `black` as a linter, failing tests if code is not formatted according to `black`'s standards. The current version is 0.6.0, with releases typically occurring on an annual to bi-annual cadence.

pip install pytest-black
INSTALL
IMPORT
SIG · PYTEST-BLACK
P
pytest-black
testingpythonv0.6.0
Install
3.3s avg
Import
Disk
36MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 34.7MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.3s · import 0.000s · 40MB
36MB installed
● package 36MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pytest_black plugin activation
Install 'pytest-black' and run 'pytest --black'
pytest-black is a pytest plugin that extends pytest's command-line interface. It does not expose Python symbols (classes, functions) for direct import into user test files or application code. Its functionality is primarily controlled via pytest flags.

To quickly start using pytest-black, install the plugin along with black and pytest. Then, simply run pytest with the `--black` flag. pytest-black will check all Python files found by pytest for black compliance. If any files are unformatted, tests will fail.

import pytest # Create a test file (e.g., test_example.py) # with some unformatted code: # def test_hello(): # print( 'Hello, World!') # assert True # To run: # 1. Save the above unformatted code in test_example.py # 2. Run in terminal: pip install pytest-black black pytest # 3. Run in terminal: pytest --black # Expected output for unformatted code would include black errors. # If code is formatted, it would pass without black errors.
Debug
Known issues
gotchapytest-black checks formatting but does NOT automatically reformat code. It merely reports formatting violations.
fix
To fix formatting, manually run `black .` in your project root after `pytest --black` reports issues.
affects: All versions
gotchaThe plugin is only active when the `--black` flag is explicitly passed to pytest. Running `pytest` without this flag will not perform any black checks.
fix
Always use `pytest --black` to enable formatting checks. Consider adding it to your CI/CD pipeline or as a pre-commit hook.
affects: All versions
gotchaEnsure that the `black` package itself is installed in the same environment where `pytest` and `pytest-black` are running. `pytest-black` depends on `black` being available.
fix
Make sure to include `pip install black` alongside `pytest` and `pytest-black` in your setup, e.g., `pip install pytest pytest-black black`.
affects: All versions
Upgrade
Version history
0.6.0latest on PyPI · released Dec 15, 2024
Audit
Dependencies
blackrequiredRequired for formatting checks; pytest-black uses it as an internal dependency.
pytestrequiredpytest-black is a plugin for pytest and requires it to run.
Agent activity
12 hits · last 30 days
node
10
Resources
pytest-black — pip install pytest-black · libregistry