Registry / testing / coverage-conditional-plugin

coverage-conditional-plugin

JSON →
library0.9.0pypypiunverified

Coverage Conditional Plugin allows defining conditional coverage rules based on any Python expressions or environment variables. It helps to omit specific lines, functions, or entire modules from coverage reports based on custom logic. As of version 0.9.0, it officially supports Python 3.7+ and Coverage.py 7.x, enabling highly customizable control over what gets included in your coverage reports.

pip install coverage-conditional-plugin coverage
INSTALL
IMPORT
SIG · COVERAGE-CONDITION
C
coverage-conditional-plugin
testingpythonv0.9.0
Install
2.3s avg
Import
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.915 runs
installs and imports cleanly · install 0.0s · import 0.000s · 20MB
glibc
py 3.103.915 runs
installs and imports cleanly · install 2.3s · import 0.000s · 21MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_env_info
from coverage_conditional_plugin.plugin import get_env_info
This function allows programmatic inspection of the plugin's environment and rules, primarily for debugging or advanced integration, not for standard configuration.

To use the plugin, you must configure it within your `coverage.py` settings, typically in `pyproject.toml` or `.coveragerc`. Define `rules` as Python expressions that determine when lines or blocks of code should be omitted from coverage reports. These rules can reference `os.getenv`, `sys.version_info`, and other global Python context variables.

import os import sys from coverage_conditional_plugin.plugin import get_env_info # --- Example of programmatic usage (less common, for debugging) --- print("\n--- Plugin Environment Info ---") print(get_env_info()) print("--------------------------------\n") # --- Typical usage: configure via pyproject.toml or .coveragerc --- # Create a `pyproject.toml` file in your project root with this content: # # [tool.coverage.run] # plugins = ["coverage_conditional_plugin"] # # [tool.coverage.coverage_conditional_plugin] # # Example rule 1: omit lines if Python version is below 3.8 # rules = [ # "if sys.version_info < (3, 8): omit", # # Example rule 2: omit lines starting with 'def debug_feature' if env var is 'true' # "if os.getenv('SKIP_DEBUG_FEATURES', 'false') == 'true': exclude_lines_starting_with('def debug_feature')", # ] # # Create a dummy Python file (e.g., `my_app.py`) to demonstrate: # def standard_feature(): # print("This is always covered.") # # def debug_feature(): # print("This is a debug-only function.") # Will be excluded if SKIP_DEBUG_FEATURES is 'true' # # if sys.version_info >= (3, 8): # print("Running on Python 3.8 or newer.") # This line would be omitted if Python < 3.8 # else: # print("Running on Python older than 3.8.") # # standard_feature() # debug_feature() # --- To run this example from your terminal --- # 1. Make sure you have `pyproject.toml` and `my_app.py` in your current directory. # 2. Run coverage normally (all lines covered, assuming Python >= 3.8): # $ coverage run my_app.py # $ coverage report -m # # 3. Run coverage with an environment variable rule activated: # $ SKIP_DEBUG_FEATURES=true coverage run my_app.py # $ coverage report -m # (Expected: `debug_feature` lines are now marked as omitted/excluded) # Note: The Python code in this block is for demonstration and `get_env_info()` execution. # The primary interaction is via `coverage.py` configuration and shell commands.
Debug
Known issues
breakingVersion 0.9.0 and newer of the plugin officially support only `coverage.py` version 7.x. Using plugin versions >=0.8.0 with `coverage.py` 6.x or older versions may lead to compatibility issues or errors.
fix
Ensure your `coverage.py` version matches the plugin's requirements. For `coverage-conditional-plugin>=0.8.0`, upgrade `coverage.py` to `7.x` (`pip install "coverage>=7.0,<8.0"`). For older plugin versions, consider pinning `coverage.py` 6.x or upgrading the plugin.
affects: >=0.8.0
breakingSupport for Python 3.6 was dropped in version 0.6.0. If you are using Python 3.6, you must use an older version of the plugin.
fix
Upgrade your Python environment to 3.7 or newer, or if you must remain on Python 3.6, pin `coverage-conditional-plugin<0.6.0`.
affects: >=0.6.0
gotchaThe ability to configure the plugin via `pyproject.toml` (under `[tool.coverage.coverage_conditional_plugin]`) was introduced in version 0.3.0. Older versions (<0.3.0) exclusively supported configuration through `.coveragerc`.
fix
For modern projects, use `pyproject.toml` for configuration. If working with an older plugin version, ensure your configuration is correctly placed in a `.coveragerc` file.
affects: <0.3.0
gotchaThe `omit` feature, which allows you to omit entire modules from coverage directly via the configuration file (e.g., `[tool.coverage.coverage_conditional_plugin.omit]`), was added in version 0.9.0.
fix
Upgrade to `coverage-conditional-plugin>=0.9.0` to utilize the module-level `omit` configuration section.
affects: <0.9.0
Upgrade
Version history
0.9.0latest on PyPI · released Jun 2, 2023
Audit
Dependencies
coveragerequiredThis plugin extends Coverage.py and is strictly dependent on it. Version 7.x is officially supported with plugin version >= 0.8.0.
packagingrequiredUsed internally for version parsing and compatibility checks (added in 0.3.1).
Agent activity
12 hits · last 30 days
node
10
Bingbot
1
OpenAI (training)
1
Resources
coverage-conditional-plugin — pip install coverage-conditional-plugin · libregistry