navigation

testmon on your machine

pip install pytest-testmon

# first run: all tests, records the dependencies in .testmondata
pytest --testmon

# next runs: only the tests affected by your changes
pytest --testmon

Before testmon can select tests, it has to see all of them run once with --testmon. Tests that failed last time always run again. To run the tests on every file save, combine testmon with pytest-watch.

Options

optioneffect
--testmonselect the tests affected by changes, and record new data in .testmondata; selection or recording may be turned off automatically, see below
--testmon-noselectrun all tests, the ones most likely to fail first; forced if you use -m, -k, --lf or explicit test ids such as test_file.py::test_name
--testmon-forceselectselect only the tests that are affected and also match the pytest selectors
--testmon-nocollectselect, but don’t record; forced under a debugger or coverage
--testmon-env=<name>keep separate data for environments that run the same sources, e.g. different Django settings
--no-testmonturn testmon off, even if the configuration turns it on; forced if it can neither select nor record (debugger plus test selector)
--tmnetkeep the data in testmon.net instead of .testmondata

Configuration

To make testmon the default, add it to your pytest configuration:

[pytest]
addopts = --testmon

To keep .testmondata somewhere other than the pytest rootdir, set the TESTMON_DATAFILE environment variable.

Troubleshooting

testmon selects too many tests. Most likely by design. If you change a method’s parameter name, you change the method, its class and its module, so every test that uses anything from that module runs again.

Tests fail under testmon. testmon is unlikely to change how a test runs. But the set of tests it runs differs from run to run, which exposes tests that depend on each other. Fix the test suite; tips are in Hidden test dependencies. You can also check whether the test fails under pytest-cov without testmon.

To report a bug, a repository that reproduces it is best, but please report it even if your project is closed source: issues.

What testmon tracks

testmon tracks:

  1. the code of the tested project itself
  2. the environment: Python version and environment variables such as DJANGO_SETTINGS_MODULE (separate them with --testmon-env)
  3. the versions of installed packages

testmon does not track:

  1. static files (txt, xml, other project assets)
  2. external services reached through the network