Registry / testing / pytest-testmon

pytest-testmon

JSON →
library2.2.0pypypiunverified

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.

pip install pytest-testmon
INSTALL
IMPORT
SIG · PYTEST-TESTMON
P
pytest-testmon
testingpythonv2.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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
pytest --version
Debug
Known issues
breakingAfter upgrading pytest-testmon to a new version, the `.testmondata` file might be in an incompatible format. It's crucial to remove this file to avoid issues and allow a new database to be built.
fix
Delete the `.testmondata` file from your project's root directory after each upgrade: `rm .testmondata`.
affects: <=2.1.x to 2.2.0 (and potentially future major/minor upgrades)
gotchaWhen combining `pytest-testmon` with `pytest-watch` for continuous testing, `testmon` can become out of sync if interrupted, leading to incomplete results. This is because `testmon` is stateful.
fix
When using with `pytest-watch`, consider running `pytest --testmon --testmon-readonly`. This uses a frozen snapshot of the dependency data and prevents `testmon` from updating its database during `pytest-watch` runs, ensuring consistent test selection.
affects: All versions
gotchapytest-testmon may re-execute more tests than anticipated, especially if changes are made to fundamental parts of the codebase like method parameter names. This is often by design, as such changes can have broad impacts.
fix
Understand that `testmon` identifies dependencies at a fine-grained code block level. A seemingly small change to a widely used function or module might correctly trigger many dependent tests. If tests are failing unexpectedly, it might indicate underlying undesired test dependencies in your test suite, which `testmon` helps expose.
affects: All versions
gotchaFor `pytest-testmon` to effectively select a subset of tests, an initial full run of your test suite with the `--testmon` option is required to build its dependency database.
fix
Always perform an initial `pytest --testmon` run to populate the `.testmondata` file before expecting `testmon` to intelligently select tests.
affects: All versions
deprecatedThe `run_variants` configuration option was removed in version 0.4+. It has been replaced by `run_variant_expression` for separating coverage data for different environments.
fix
Update your configuration (e.g., in `pytest.ini`) to use `run_variant_expression` instead of `run_variants`. For example: `run_variant_expression = os.environ.get('DJANGO_SETTINGS_MODULE') + ':python' + str(sys.version_info[:2])`.
affects: <0.4
Upgrade
Version history
2.2.0latest on PyPI · released Dec 1, 2025
Audit
Dependencies
pytestrequiredpytest-testmon is a plugin for pytest.
coveragerequiredUsed internally by pytest-testmon to collect code execution data.
pytest-watchoptionalOften used in conjunction for continuous test execution, though specific usage caveats apply.
Agent activity
7 hits · last 30 days
node
6
Resources
pytest-testmon — pip install pytest-testmon · libregistry