Pytest Incremental Test Runner
Pytest-incremental is a pytest plugin designed to accelerate test execution by identifying and running only the tests affected by recent code changes. It achieves this by analyzing project structure and file modifications between test runs, reordering test execution and de-selecting unaffected tests. The project is currently at version 0.6.0, but it is officially deprecated and no longer actively maintained.
Common errors
-
pytest: error: unrecognized arguments: --inc
cause The 'pytest-incremental' plugin is not installed in the current environment or pytest cannot locate it.fixInstall the plugin: `pip install pytest-incremental` -
Pytest is running all tests even when only a small change was made, or tests that should be skipped are still running.
cause Pytest-incremental is not correctly detecting dependencies due to factors like dynamic imports, monkey-patching, cyclic dependencies, or an incompatibility with your current pytest version.fixReview your codebase for dynamic import patterns or cyclic dependencies. Ensure your pytest and pytest-incremental versions are compatible. Consider enabling verbose output (`pytest --inc -v`) to understand what the plugin is doing. If issues persist, consider using the recommended replacement 'rut' or 'pytest-testmon'.
Warnings
- breaking The pytest-incremental project is officially DEPRECATED and no longer maintained. A replacement project, 'rut' (built on unittest directly), is being developed by the original author. Users should consider migrating or using alternative incremental test runners.
- gotcha Pytest-incremental relies on AST analysis to detect dependencies. Dynamic aspects of Python, such as `importlib` usage, non-explicit imports, or extensive monkey-patching, may prevent it from accurately detecting all dependencies, leading to incomplete test runs or undetected changes.
- gotcha Projects with cyclic dependencies will negatively affect the efficacy of pytest-incremental, as any change in a module within a cycle may lead to all modules in the cycle (and their dependents) being re-executed.
- gotcha The plugin was last officially tested with Python 3.6-3.9 and pytest 6.x. While it may still function with newer Python and pytest versions (e.g., pytest 8.3.3 with Python 3.10.12), compatibility is not guaranteed or officially supported due to the project's deprecated status.
Install
-
pip install pytest-incremental
Quickstart
import os # To use pytest-incremental, simply run pytest with the --inc flag. # Example command line usage: # pytest --inc # Alternatively, enable it by default in your pytest.ini: # [pytest] # addopts = --inc # To watch for changes in modules outside the current working directory: # pytest --inc --inc-path my_lib --inc-path ../py3rd-trunk/py3rd # To visualize detected dependencies (requires graphviz): # pytest --inc-graph-image