Troubleshooting¶
This guide documents common errors you may encounter when using pytest-gremlins, along with their causes and solutions.
Installation Errors¶
Error: Python version not supported¶
Symptom:
Or when using pip:
Cause: pytest-gremlins requires Python 3.11 or later. You are running an older Python version.
Solution:
- Check your Python version:
- Install Python 3.11 or later:
# macOS with Homebrew
brew install python@3.11
# Ubuntu/Debian
sudo apt install python3.11
# Using pyenv
pyenv install 3.11.0
pyenv local 3.11.0
- Create a virtual environment with the correct Python:
Prevention: Always verify your Python version meets requirements before installing packages.
Error: Dependency conflict with pytest¶
Symptom:
Or pip resolver errors mentioning pytest version conflicts.
Cause: Your project has an older version of pytest pinned that conflicts with pytest-gremlins requirements.
Solution:
- Upgrade pytest:
- If you have version constraints in your
pyproject.tomlorrequirements.txt, update them:
- Re-install pytest-gremlins after upgrading pytest.
Related: Getting Started
Error: Dependency conflict with coverage.py¶
Symptom:
Cause: Your project has an older version of coverage.py that doesn't support the features pytest-gremlins needs (like dynamic contexts for test selection).
Solution:
- Upgrade coverage:
- If using pytest-cov, ensure it's also up to date:
Prevention: Use a dependency manager like uv or poetry that handles transitive dependencies correctly.
Configuration Errors¶
Error: Unknown operator requested¶
Symptom:
(Note: no gremlins found because the operator name was misspelled)
Cause: You specified an operator name in configuration that doesn't exist. Common causes:
- Typo in operator name
- Using a deprecated operator name
- Missing a custom operator registration
Solution:
-
Check the correct operator names. Available operators are:
-
comparison(not "comparision") arithmeticbooleanboundary-
return -
Fix your configuration:
- Or on the command line:
Related: Operators
Error: No source paths discovered¶
Symptom:
No gremlins found, even though your code has mutable expressions.
================== pytest-gremlins mutation report ==================
No gremlins found: no source paths were discovered.
pytest-gremlins looks for source code in this order:
1. --gremlin-targets CLI option
2. [tool.pytest-gremlins] paths in pyproject.toml
3. [tool.setuptools] package config in pyproject.toml
4. [project].name heuristic
5. setup.cfg packages config
6. importlib.metadata (installed package metadata)
7. src/ directory
If your source code is elsewhere, use: pytest --gremlins --gremlin-targets=your_package
=====================================================================
Cause: pytest-gremlins could not auto-discover your source code. This happens when:
- You don't have a
pyproject.toml(e.g., usingrequirements.txt) - Your
pyproject.tomldoesn't have[tool.setuptools]configuration - Your source code is not in a
src/directory
Solution:
- Point directly at your source code:
Prevention: Always verify your project structure matches your configuration.
Error: TOML syntax error in pyproject.toml¶
Symptom:
tomllib.TOMLDecodeError: Expected '=' after a key in a key/value pair (at line X, column Y)
Cause: Invalid TOML syntax in your configuration file.
Solution:
- Validate your TOML syntax. Common mistakes:
# WRONG - missing quotes around string
[tool.pytest-gremlins]
operators = [comparison, arithmetic]
# CORRECT
[tool.pytest-gremlins]
operators = ["comparison", "arithmetic"]
-
Check for mismatched brackets or unclosed strings.
-
Use a TOML validator or IDE with TOML support.
Runtime Errors¶
Error: SyntaxError during instrumentation¶
Symptom:
Or the mutation testing silently skips certain files.
Cause: pytest-gremlins couldn't parse a Python file. This typically happens when:
- The file contains syntax errors
- The file uses Python features newer than your Python version
- The file is not valid UTF-8
Solution:
- Run your tests without mutation testing first to catch syntax errors:
- Check that all files can be parsed:
- Ensure consistent encoding (UTF-8) in all source files.
Prevention: Set up pre-commit hooks to validate syntax before committing.
Error: AST transformation produces unexpected result¶
Symptom:
Cause: Internal error during AST transformation. This is rare and typically indicates:
- An edge case in the code structure
- A bug in pytest-gremlins (please report it!)
Solution:
- Try excluding the problematic file temporarily:
- Report the issue with a minimal reproduction at: https://github.com/mikelane/pytest-gremlins/issues
Related: Contributing
Error: Cache database corrupted¶
Symptom:
Cause: The SQLite cache database was corrupted. This can happen due to:
- Process termination during a write
- File system issues
- Concurrent access from multiple processes
Solution:
This warning is informational - pytest-gremlins automatically recreates the cache. No action required.
To manually clear the cache:
Or delete the cache directory:
Prevention: Avoid forcefully killing pytest-gremlins during execution.
Error: Test timeout exceeded¶
Symptom:
Gremlin results show TIMEOUT status, or you see:
Cause: A test took longer than the configured timeout (default: 30 seconds) when running with a mutation active.
Common causes:
- Mutation caused an infinite loop
- Mutation caused extremely slow computation
- Test is inherently slow
- System under heavy load
Solution:
- The default timeout is 30 seconds (currently not configurable). Identify slow tests and optimize them:
- Exclude specific slow tests from mutation testing using pytest marks.
Prevention: Keep individual tests fast (under 1 second when possible).
Error: Memory issues with large codebases¶
Symptom:
Or the system becomes unresponsive during mutation testing.
Cause: pytest-gremlins instruments all source code at once, which can consume significant memory for large codebases.
Solution:
- Run mutation testing on specific paths:
- Reduce the number of parallel workers:
- Run mutation testing in batches by module:
- Exclude non-critical code:
Prevention: Start with a subset of code and expand gradually.
Error: RuntimeError - WorkerPool is not active¶
Symptom:
Or:
Cause: Internal error - the parallel worker pool was accessed outside its context manager.
Solution:
This indicates a bug in pytest-gremlins. Please:
-
Report the issue with full traceback at: https://github.com/mikelane/pytest-gremlins/issues
-
As a workaround, disable parallel execution:
Error: Invalid pool configuration¶
Symptom:
ValueError: Invalid start method: 'forkk'. Valid methods are: ['auto', 'fork', 'forkserver', 'spawn']
Or:
Or:
Cause: Invalid configuration values for parallel execution settings.
Solution:
Use valid configuration values via CLI arguments:
--gremlin-workers: A positive integer (or omit to use CPU count)--gremlin-batch-size: A positive integer (default: 10)
Since v1.5.0, workers and batch_size are configurable via pyproject.toml. See
Configuration for the full list of keys.
Integration Errors¶
Error: Conflict with pytest-cov¶
Symptom:
Coverage numbers are incorrect or missing when running mutation testing.
Cause: Both pytest-gremlins and pytest-cov try to collect coverage data, which can conflict.
Solution:
- Disable pytest-cov when running mutation testing:
- Or configure them to not run together:
# pytest.ini or pyproject.toml [tool.pytest.ini_options]
addopts = --cov=src # only for regular test runs
- Run them separately:
# Regular tests with coverage
pytest --cov=src
# Mutation testing (has its own coverage collection)
pytest --gremlins --no-cov
Prevention: Use separate pytest invocations for coverage and mutation testing.
Using pytest-xdist with gremlins¶
Since v1.5.0, --gremlins and -n work together. The recommended way to run parallel
mutation testing is:
This uses a two-phase model: Phase 1 distributes your test suite across xdist workers; Phase 2 reuses xdist's resolved worker count for mutation evaluation.
Common issues:
Workers crash or hang with -n auto:
Reduce the worker count to give each process more memory:
You want parallel mutations without xdist test distribution:
Use the built-in worker pool instead:
pytest --gremlins --gremlin-parallel # all CPU cores
pytest --gremlins --gremlin-workers=4 # explicit count
Running without xdist installed:
pytest-gremlins operates in single-worker mode when xdist is absent. No error is raised.
Error: SyntaxError with from __future__ import annotations¶
Symptom:
Cause: In versions before v1.5.0, gremlin injection could insert code before __future__
imports. Python requires __future__ imports to appear before any other statements.
Solution:
Upgrade to v1.5.0 or later. The instrumentation engine now inserts gremlin switches after
__future__ imports at the AST level, so this error no longer occurs.
Low code coverage numbers for pytest-gremlins itself¶
Symptom:
When running coverage on pytest-gremlins itself (as a contributor), you see lower coverage than expected (around 69%) despite comprehensive tests.
Cause: This is an inherent limitation of measuring code coverage for pytest plugins, not a testing gap. The issue occurs because:
-
Plugin import timing: When pytest loads a plugin, it imports the entire module tree before coverage.py starts instrumenting code. Module-level imports, constants, and function definitions execute during loading, so they show as uncovered.
-
Multiprocessing code paths: Worker pool code runs in subprocesses where coverage measurement is complex to coordinate.
-
Integration tests: pytester (the pytest integration test fixture) runs pytest in isolated subprocesses, which don't share coverage data with the main process.
Solution:
This is expected behavior, not a bug. The test suite is comprehensive:
- Files like
results.pyandscore.pyhave full test coverage intests/small/reporting/ - The 69% coverage target reflects what's measurable, not test quality
- Function bodies are measured when tests call them; only function definitions appear uncovered
For contributors: see the Code Coverage section in CONTRIBUTING.md for details on our coverage configuration.
Related: Contributing Guide
Error: Coverage collection fails¶
Symptom:
For gremlins that should be covered by tests.
Cause: Coverage collection failed to map tests to source lines. Common causes:
- Source files are outside the coverage measurement scope
- Tests import modules before coverage starts
- Dynamic imports that bypass coverage
Solution:
- Verify coverage is working normally:
- Ensure source paths match what pytest-gremlins expects:
- Check for import order issues in conftest.py.
Error: IDE integration issues¶
Symptom:
IDE shows errors or warnings about instrumented code, or debugging doesn't work correctly during mutation testing.
Cause: pytest-gremlins modifies code at runtime, which IDEs can't see.
Solution:
- For debugging: Run without mutation testing first:
-
For IDE analysis: The original source is unchanged; IDE analysis should work normally on your source files.
-
For test discovery: pytest-gremlins doesn't affect test discovery. If tests aren't discovered, check your IDE's pytest configuration.
Error: CI/CD environment issues¶
Symptom:
Mutation testing works locally but fails in CI with:
- Permission errors
- Missing dependencies
- Timeout errors
Cause: CI environments have different configurations than local development.
Solution:
- Permission errors: Ensure the CI user can write to the cache directory:
-
Timeout errors: The timeout is currently fixed at 30 seconds. If tests are timing out, optimize them or exclude slow tests from mutation testing.
-
Memory limits: Reduce parallelism:
- Cache not persisting between runs: Store the cache as an artifact:
# GitHub Actions
- uses: actions/cache@v3
with:
path: .gremlins_cache
key: gremlins-cache-${{ hashFiles('src/**/*.py') }}
Getting Help¶
Debugging Tips¶
- Enable verbose output:
- Run on a single file first:
- Generate an HTML report for detailed results:
Then open coverage/gremlins/index.html in your browser for a detailed breakdown of all gremlins and
their status.
- Disable caching to rule out cache issues:
Reporting Issues¶
If you encounter a bug not covered here:
-
Search existing issues: https://github.com/mikelane/pytest-gremlins/issues
-
Create a new issue with:
-
pytest-gremlins version (
pip show pytest-gremlins) - Python version (
python --version) - Operating system
- Full error traceback
- Minimal code to reproduce the issue
-
Configuration (pyproject.toml snippet)
-
Include your environment:
Community Resources¶
- GitHub Discussions: https://github.com/mikelane/pytest-gremlins/discussions
- Issue Tracker: https://github.com/mikelane/pytest-gremlins/issues
Related Documentation¶
- Getting Started - Installation and first run
- Configuration - All configuration options
- Operators - Mutation operator reference
- Reports - Understanding output and reports