pytest-testmon is an MIT-licensed pytest plug-in, written in Python, that automatically selects and re-executes only the tests affected by recent code changes, so developers and CI pipelines run the right tests first instead of the whole suite.
What it is
pytest-testmon is a plug-in for pytest, the Python test runner. While tests execute, the plug-in collects dependency data and builds a database; on later runs it uses that data to pick only the tests touched by recent edits. It installs from PyPI as pytest-testmon and activates through the --testmon flag, storing its state in a file named .testmondata. The project lives in the pytest ecosystem, carries the topics build-tool, ci, python, test-automation and testing, and documents its options at testmon.org. The repository currently shows 1015 stars, 81 forks and 38 open issues, with the last push on 2025-12-01.
The concrete problem it solves is the full-suite re-run. On a large Python codebase, running every test after every edit costs time that the editor usually does not need, because most tests are unrelated to the change. pytest-testmon replaces that blanket re-run with an affected-test selection step, and the README acknowledges the obvious difficulty: selecting tests in a dynamic language like Python is not a trivial static-analysis exercise. The project answers that concern with a dedicated write-up, "Determining affected tests", linked from the README, and it states the reliability question openly rather than hiding it.
Key capabilities
- Installs as a pytest plug-in with
pip install pytest-testmon and runs through pytest --testmon.
- Builds a dependency database and saves it to
.testmondata on the first run, then reuses it on subsequent runs.
- Re-executes only the tests affected by recent changes, rather than the entire suite.
- Executes the right tests first, ordering the selected set by relevance.
- Acts as a continuous test runner when paired with pytest-watch.
- Supports additional options, documented at testmon.org, beyond the default
--testmon invocation.
- Offers a CI adoption programme: the maintainers run testmon inside a project, prepare the pull request, and set it up so that no tests are deselected initially.
Who uses it and how
- Developers in a local edit-test loop: change code, run
pytest --testmon, and get only the tests that the change affects.
- CI pipelines, matching the repository's
ci topic, where trimming a slow Python suite shortens feedback time.
- Teams wanting continuous testing, running pytest under pytest-watch so affected tests re-execute as files change.
- Open-source maintainers who join the CI programme, where the project is instrumented, data is collected, and deselection is introduced only when the reliability and time savings justify it.
- Projects with large Python suites where running every test on every commit is the main bottleneck.
Getting started
Install the plug-in from PyPI with pip install pytest-testmon, then run pytest --testmon. The first run builds the dependency database in .testmondata, and later runs execute only the tests affected by recent changes.
How it compares
The facts provide no list of paid products that pytest-testmon replaces, and they name no similar test-selection tool. Within this registry it stands alone: it is the only entry here described as a pytest plug-in for affected-test selection.
When to use it — and when not
A self-hoster needs a working Python environment with pytest, plus a .testmondata file that is generated on first run and kept between runs; no external database, object storage or SMTP service is mentioned anywhere in the facts. It is not for non-Python suites, and it is not for teams running a non-pytest test runner, since the whole mechanism depends on pytest. Two honest caveats: the README is short and pushes most documentation to testmon.org, so users depend on that site, and the project itself frames selection accuracy in dynamic Python as still being collected and improved through its CI programme, which means the affected-test set should be treated as a heuristic rather than a guarantee.