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.
| option | effect |
|---|---|
--testmon | select the tests affected by changes, and record new data in .testmondata; selection or recording may be turned off automatically, see below |
--testmon-noselect | run 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-forceselect | select only the tests that are affected and also match the pytest selectors |
--testmon-nocollect | select, 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-testmon | turn testmon off, even if the configuration turns it on; forced if it can neither select nor record (debugger plus test selector) |
--tmnet | keep the data in testmon.net instead of .testmondata |
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.
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.
testmon tracks:
DJANGO_SETTINGS_MODULE (separate them with --testmon-env)testmon does not track: