skillfed

coverage-conditional-plugin

Conditional coverage based on any rules you define!

coverage-conditional-plugin v0.9.0 169.1K downloads/30d#10,429 on PyPI80
Permissive license MIT DORMANT released

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-plugin

uv

uv add coverage-conditional-plugin

poetry

poetry add coverage-conditional-plugin

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python Modules

Tags

coverage.py plugin conditionalenvironment-based coverage exclusionpragma coverage rulespython version coverageconditional code coveragecoverage based on environment markersdynamic coverage omit
coverage-measurementtesting-infrastructuremulti-environment

More Python Modules packages