coverage-conditional-plugin
Conditional coverage based on any rules you define!
What it is and what it does
coverage-conditional-plugin extends coverage.py to mark code as covered or uncovered based on runtime conditions rather than static pragmas. Instead of using `# pragma: no cover` for code that only runs on certain Python versions, operating systems, or when specific packages are installed, you define named rules (e.g., `"sys_version_info >= (3, 8)": py-gte-38`) in your coverage configuration, then annotate code with `# pragma: py-gte-38`. The plugin evaluates the condition at test time and includes or excludes that code from coverage accordingly.
It supports environment markers from PEP 496 (Python version, OS, platform), custom functions like `is_installed()` to check for optional dependencies, and `package_version()` to version-gate code. You can also conditionally omit entire files based on conditions. This is useful for projects with platform-specific code, version-specific features, or optional dependencies—you can achieve 100% coverage in multiple test environments without littering your code with unconditional pragmas.
Use it for:
- Mark Windows-only or Linux-only code blocks so they are only counted as covered when tests run on that platform.
- Exclude code that only executes on Python 3.7 from coverage when testing on Python 3.10+, and vice versa.
- Include or exclude optional-dependency code (e.g., Django integration) based on whether the package is installed in the test environment.
- Achieve 100% coverage across multiple CI jobs that test different Python versions or OS combinations without false negatives.
- Version-gate code paths so that code for a deprecated feature version is only measured when that version is present.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A coverage.py plugin that applies conditional coverage rules based on environment markers, Python version, installed packages, or custom conditions, allowing code to be included or excluded from coverage measurement dynamically.
Yes, if you maintain a multi-environment test suite (different Python versions, OSes, or optional dependencies) and want accurate coverage reporting across all of them. The low install friction and permissive license make adoption straightforward. However, the dormant maintenance status (last release June 2023, no recent commits) means you should verify compatibility with your current coverage.py and Python versions before relying on it in production CI—consider forking or monitoring the upstream repository if you need active support.
Install
coverage-conditional-plugin on PyPI
pip
pip install coverage-conditional-pluginuv
uv add coverage-conditional-pluginpoetry
poetry add coverage-conditional-pluginInstalling coverage-conditional-plugin
Before you install
Low install friction; pure Python wheel with three straightforward runtime dependencies (coverage, packaging, importlib_metadata). Maintenance is dormant—last release was 2023-06-02 and no commits since 2025-01-03—so expect no active bug fixes or feature updates, though the codebase appears stable.
License in practice
MIT license (permissive) means you can use, modify, and distribute this package freely in commercial or private projects with minimal restrictions, provided you retain the license notice.
Quickstart
pip install coverage-conditional-plugin
# In setup.cfg or .coveragerc:
[coverage:run]
plugins = coverage_conditional_plugin
[coverage:coverage_conditional_plugin]
rules =
"sys_version_info >= (3, 8)": py-gte-38
"is_installed('django')": has-django
# In your code:
# pragma: py-gte-38
some_code_for_python_38_plus()
# pragma: has-django
django_specific_code()
Requires coverage to be installed and configured in your project; the plugin integrates via coverage.py's plugin system and must be declared in setup.cfg, .coveragerc, or pyproject.toml.
Verify before relying
- Whether the plugin works correctly with all coverage.py versions currently in use (fact sheet does not specify coverage version constraints).
- Performance impact when evaluating many conditional rules across a large codebase.
- Whether dormant maintenance status affects compatibility with recent Python or coverage.py releases.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.7,<4.0) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — coverage, packaging, importlib_metadata |
| Maintenance | dormant — 1,169 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 169,080/month — #10,429 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: coverage_conditional_plugin-0.9.0-py3-none-any.whl
Keywords: coverage, coverage.py, pytest-cov, testing
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
conditionalConditionally apply a context manager to a code…
permissive · top 15,000 on PyPI
covdefaultsA coverage plugin that automatically applies…
permissive · top 15,000 on PyPI
update_checkerChecks whether a whitelisted Python package has…
permissive · top 5,000 on PyPI
django-coverage-pluginA coverage.py plugin that measures test…
permissive · top 5,000 on PyPI
coverage_enable_subprocessInstalls a .pth file that automatically enables…
permissive · top 15,000 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-skip-markersA pytest plugin that provides skip markers to…
permissive · top 15,000 on PyPI
pytest-enablerA pytest plugin that conditionally enables…
permissive · top 15,000 on PyPI
pytest-coverpytest-cover is a pytest plugin for measuring…
permissive · top 15,000 on PyPI
mypy-strict-kwargsA mypy plugin that enforces…
permissive · top 15,000 on PyPI