Registry / testing / pytest-ruff

pytest-ruff

JSON →
library0.5pypypiunverified

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.

pip install pytest-ruff
INSTALL
IMPORT
SIG · PYTEST-RUFF
P
pytest-ruff
testingpythonv0.5
Install
3.4s avg
Import
Disk
30MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5 · 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 · 31.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.4s · import 0.000s · 32MB
30MB installed
● package 30MB
Code
Verified usage

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

pytest-ruff
This is a pytest plugin and does not typically require direct Python imports in user code. Its functionality is enabled via pytest command-line arguments.
Users interact with pytest-ruff primarily through pytest CLI flags like `--ruff` and `--ruff-format`, not via Python import statements.

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.
Debug
Known issues
breakingThe `--show-source` CLI argument for controlling source code snippets in Ruff's output was replaced by `--output-format` in `pytest-ruff v0.4.0`. Using the old flag will result in an 'unrecognized arguments' error.
fix
Update your pytest command or configuration to use `--output-format` instead of `--show-source`. For example, `pytest --ruff --output-format=full`.
affects: >=0.4.0
gotchaIn versions prior to `v0.2.1`, the `--ruff` and `--ruff-format` flags might not have worked independently or as expected, potentially leading to inconsistent behavior.
fix
Upgrade to `pytest-ruff v0.2.1` or newer to ensure `--ruff` and `--ruff-format` operate as distinct checks as intended.
affects: <0.2.1
gotchaTests generated by `pytest-ruff` (and similar quality assurance plugins) might not always respect pytest's `-k` expression for selecting a subset of tests. This means Ruff checks could run even when you're trying to target specific functional tests, potentially slowing down development in large projects.
fix
Be aware that `-k` might not skip Ruff checks. If this is a significant performance bottleneck, consider running Ruff separately via `ruff check .` and `ruff format --check .` outside of your `pytest` invocation for focused test runs.
affects: All versions
gotchaRuff's `F401` (unused import) rule can sometimes incorrectly flag imported pytest fixtures as unused, especially if the fixtures are imported but not directly called in the test function body (e.g., when relying on implicit fixture injection).
fix
You can add `# noqa: F401` to the line importing the fixture if you're sure it's being used implicitly by pytest. Alternatively, consider using `conftest.py` for shared fixtures or `pytest.mark.usefixtures()` for fixtures whose return value isn't directly consumed to make the dependency explicit and potentially avoid the `F401` warning.
affects: All versions
Upgrade
Version history
0.5latest on PyPI · released Jun 19, 2025
Audit
Dependencies
pytestrequiredRequired as pytest-ruff is a plugin for the pytest testing framework.
ruffrequiredRequired as pytest-ruff wraps and runs the Ruff linter and formatter.
Agent activity
13 hits · last 30 days
node
12
Resources
pytest-ruff — pip install pytest-ruff · libregistry