covdefaults
covdefaults is a coverage.py plugin that provides sensible, opinionated default settings to streamline test coverage configuration. It automatically sets defaults for aspects like branch coverage, source directory, common file omission patterns, and reporting options (e.g., `show_missing=True`, `fail_under=100`). The current version is 2.3.0, released on March 5, 2023, and it maintains an active release cadence.
Warnings
- gotcha Overriding default options in coverage.py configuration files (e.g., `pyproject.toml`, `.coveragerc`) behaves differently for various settings. Some options, like `run:source` and `report:fail_under`, will entirely prevent `covdefaults` from applying its default if you set them manually. Other options, like `run:omit` and `report:exclude_lines`, will extend the defaults provided by `covdefaults` rather than overwriting them.
- gotcha The `[covdefaults] subtract_omit` option, when used in your configuration, removes specific patterns from `covdefaults`'s default `omit` list. Users sometimes mistakenly believe it adds to the `omit` list, leading to files being included in coverage that they intended to exclude.
- gotcha When using `pytest-cov`, its command-line options (e.g., `--cov=something`, `--cov-branch`) can override the `source` and `branch` settings provided by `coverage.py` or `covdefaults`. This can lead to unexpected coverage behavior if not managed carefully.
- gotcha Coverage.py, and by extension `covdefaults`, respects a specific order of precedence for configuration files: `.coveragerc`, `.coveragerc.toml`, `setup.cfg`, `tox.ini`, and `pyproject.toml`. If multiple files are present, only the first one found that contains `coverage.py` settings will be used. This can cause confusion if you expect settings from one file to be merged or to override settings in another.
Install
-
pip install covdefaults
Imports
- covdefaults
This library is a coverage.py plugin and is configured via coverage's configuration files (e.g., pyproject.toml, .coveragerc), not directly imported into Python code.
Quickstart
pyproject.toml
[tool.poetry]
name = "my-project"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"
[tool.poetry.dependencies]
python = ">=3.7,<4.0"
coverage = {extras = ["toml"], version = ">=6.0.2"}
[tool.poetry.group.dev.dependencies]
pip = "*"
pytest = "*"
covdefaults = "*"
[tool.coverage.run]
plugins = ["covdefaults"]
# Optional: Customize or override specific defaults
# source = ["."]
# omit = [".venv/*"]
# Optional: Customize reporting
# [tool.coverage.report]
# fail_under = 90