packages/pytest_changed/README.md
A pytest plugin that uses ruff analyze graph to intelligently discover and run only the tests affected by code changes.
This plugin analyzes your git changes and uses Ruff's dependency graph analysis to determine which tests need to be run. It performs a search through the dependency graph to find all files affected by your changes, then runs only the tests that could be impacted.
Run only tests affected by changes from main branch:
pytest -p packages.pytest_changed --changed-from=main
Using uv:
uv run --python 3.12 --group test pytest -p packages.pytest_changed --changed-from=main tests/
# Compare against HEAD (staged changes)
pytest -p packages.pytest_changed --changed-from=HEAD
# Compare against origin/main
pytest -p packages.pytest_changed --changed-from=origin/main
Use --collect-only to see which tests would be selected without running them:
pytest -p packages.pytest_changed --changed-from=main --collect-only tests/
Run affected tests plus all other tests:
pytest -p packages.pytest_changed --changed-from=main --include-unchanged tests/
The plugin respects pytest's normal path filtering:
pytest -p packages.pytest_changed --changed-from=main tests/_runtime/
git diff --name-only <ref> to find Python files that have changedruff analyze graph --direction dependents to build a dependency graph--changed-from=<ref>: Git reference to compare against (required to activate plugin)--include-unchanged: Also run tests that haven't changed (optional)