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-blackVerified import paths — ran on the pinned version, not inferred.
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.
To fix formatting, manually run `black .` in your project root after `pytest --black` reports issues.
Always use `pytest --black` to enable formatting checks. Consider adding it to your CI/CD pipeline or as a pre-commit hook.
Make sure to include `pip install black` alongside `pytest` and `pytest-black` in your setup, e.g., `pip install pytest pytest-black black`.