Pytest Testmon

2.2.0 · active · verified Sat Apr 11

pytest-testmon is a pytest plugin that intelligently selects and executes only tests affected by recent code changes. It operates by collecting dependencies between tests and the executed code (using Coverage.py) and storing this information in a local database (.testmondata). This database is updated on each test run, allowing the plugin to work independently of version control systems. The latest version is 2.2.0, released in late 2025.

Warnings

Install

Quickstart

To begin, install the plugin. The first run with `pytest --testmon` builds a `.testmondata` file containing the dependency database. Subsequent runs with `pytest --testmon` will then identify and execute only the tests impacted by recent code changes. For continuous integration, you might want to manage the `.testmondata` file or use `TESTMON_DATAFILE` environment variable.

# 1. Install pytest-testmon
# pip install pytest-testmon

# 2. Run all tests once to build the initial dependency database
#    This creates a .testmondata file
# pytest --testmon

# 3. Make some code changes that affect a subset of your tests

# 4. Run pytest-testmon again to execute only affected tests
pytest --testmon

# Example for CI/CD, if you want separate coverage data
# import os
# os.environ['TESTMON_DATAFILE'] = 'testmondata_ci'
# pytest --testmon

view raw JSON →