pytest-black Plugin

0.6.0 · active · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

view raw JSON →