Skippy-Cov
Skippy-cov is a pytest plugin that intelligently selects and runs only relevant tests based on the current Git diff and previously collected coverage data. It aims to speed up CI/CD pipelines by avoiding unnecessary test runs by analyzing which code changes affect which tests. The current version is 0.2.2, with releases occurring periodically to refine its Git and pytest integration.
Common errors
-
ModuleNotFoundError: No module named 'skippy_cov'
cause The skippy-cov package is not installed in your current Python environment.fixRun `pip install skippy-cov`. -
pytest: error: unrecognized arguments: --skippy-cov
cause The `skippy-cov` plugin is not being detected by `pytest`. This can happen if it's not installed, there's a version mismatch, or another plugin is interfering.fixEnsure `skippy-cov` and `pytest` are installed and up-to-date: `pip install --upgrade skippy-cov pytest`. Verify `pytest --version` shows skippy-cov as a plugin. -
Fatal: not a git repository (or any of the parent directories): .git
cause Skippy-cov was executed in a directory that is not part of a Git repository. It requires Git for its core functionality.fixInitialize a Git repository by running `git init` in your project's root directory or navigate to an existing Git repository. -
FileNotFoundError: [Errno 2] No such file or directory: 'git'
cause The Git executable is not found in your system's PATH. Skippy-cov directly invokes Git commands.fixInstall Git on your system and ensure it's accessible from your command line. For Linux: `sudo apt-get install git`, for macOS: `brew install git`, for Windows: download from git-scm.com.
Warnings
- gotcha Skippy-cov requires the project to be a properly initialized Git repository. It relies heavily on Git commands for diffing and file tracking.
- gotcha Skippy-cov is a pytest plugin and depends on `pytest` and `coverage.py` being installed in the same environment. Without them, it cannot function correctly.
- breaking In version 0.2.0, skippy-cov changed its pytest integration strategy from `pytest_collection_modifyitems` to `pytest_configure`. This might affect users with highly customized pytest plugins that interact with collection hooks.
- gotcha When using `--skippy-cov` with a diff, it expects a path to a file containing the `git diff` output, not the diff output itself directly or a branch name.
Install
-
pip install skippy-cov
Quickstart
mkdir my_skippy_project && cd my_skippy_project git init -b main pip install skippy-cov pytest coverage # Create a simple module and test file mkdir src && mkdir src/tests echo "def func_a():\n return 'A'\ndef func_b():\n return 'B'" > src/my_module.py echo "import pytest\nfrom src.my_module import func_a, func_b\n\ndef test_func_a():\n assert func_a() == 'A'\n\ndef test_func_b():\n assert func_b() == 'B'" > src/tests/test_my_module.py touch src/__init__.py src/tests/__init__.py git add . git commit -m "Initial code and tests" echo "\n--- First run: Collect all coverage data ---" pytest --skippy-cov --cov=src --cov-report=xml src/tests/ # Simulate a change to func_a and add a new test on a feature branch git checkout -b feature/new-func echo "def func_a():\n return 'A_modified'\ndef func_b():\n return 'B'\ndef func_c():\n return 'C'" > src/my_module.py echo "import pytest\nfrom src.my_module import func_a, func_b, func_c\n\ndef test_func_a():\n assert func_a() == 'A_modified'\n\ndef test_func_func_b():\n assert func_b() == 'B'\n\ndef test_func_c():\n assert func_c() == 'C'" > src/tests/test_my_module.py git add . git commit -m "Add func_c and modify func_a" echo "\n--- Second run: Run only affected tests using diff ---" # Generate a diff between 'main' branch and current 'feature/new-func' branch git diff main...feature/new-func -- src/my_module.py > /tmp/my_skippy_diff.diff pytest --skippy-cov=/tmp/my_skippy_diff.diff src/tests/ echo "Expected: Only tests related to func_a (modified) and func_c (new) should run."