pytest-ruff

0.5 · active · verified Thu Apr 16

pytest-ruff is a pytest plugin designed to integrate Ruff's powerful linting and formatting checks directly into your test suite. It automatically runs `ruff format --check` and `ruff check` as part of your `pytest` execution, failing tests if any Ruff requirements are not met. The current version is 0.5, and it maintains a consistent release cadence with updates addressing bug fixes and new features.

Common errors

Warnings

Install

Imports

Quickstart

To quickly verify `pytest-ruff` is working, create a `pyproject.toml` to configure Ruff and a `test_example.py` file with a deliberate Ruff violation. Then, run pytest with the `--ruff` flag. The test suite should report a failure originating from the Ruff check.

# Save as pyproject.toml
[tool.ruff]
# By default, Ruff enables 'E' (pycodestyle errors) and 'F' (Pyflakes rules).
# Ensure these are active or extend with your desired rules.
select = ["E", "F"]

# Save as test_example.py
def test_linting_violation():
    x = 1; y = 2  # E702: Multiple statements on one line (will be flagged by Ruff)
    assert x < y

# Run from your terminal in the same directory:
# pytest --ruff
# Expected output will show a failure due to the E702 Ruff violation.

view raw JSON →