Coverage.py will include __init__.py
in its report and show it as 0 lines, but with 100% coverage.
I want to exclude all blank files from the coverage report. I can't just add */__init__.py
to omit
as some of my __init__.py
files have code.
Coverage.py will include __init__.py
in its report and show it as 0 lines, but with 100% coverage.
I want to exclude all blank files from the coverage report. I can't just add */__init__.py
to omit
as some of my __init__.py
files have code.
From the docs and docs: "New in version 5.0: The contexts
and skip_empty
parameters." In your tox.ini
file or .coveragerc
file add the following:
[coverage:report]
skip_empty = true
"If skip_empty is true, don’t report on empty files (those that have no statements)."
"skip_empty (boolean, default False): Don’t include empty files (those that have 0 statements) in the report. See Coverage summary for more information."
This feature doesn't exist in coverage.py. Does it help that you can sort the HTML report to move 100% files to the bottom, or files with 0 statements to the bottom?
UPDATE: As of coverage.py 4.0, the --skip-covered
option is available to do exactly what is requested.
covered
or allowed for their exclusion. –
Indulge I set pyproject.toml like this:
[tool.coverage]
[tool.coverage.run]
omit = [
# omit anything in a .local directory anywhere
'*/.local/*',
'__init__.py',
'tests/*',
'*/tests/*',
# omit anything in a .venv directory anywhere
'.venv/*'
]
[tool.coverage.report]
skip_empty = true
You can set the .coveragerc file like this:
[run]
omit = test/* \
*\__init__.py
or
[run]
omit = com*\__init__.py \
test/*
it seems that omit do not allow pattern startwith asterisk (*)
[run]
section, e.g.: omit = */__init__.py
. I'm using pytest 5.0.1 and cov
-plugin version 2.7.1 (i.e. pytest-cov). –
Specialism coverage report
now supports the --skip-empty
directive, which will conveniently omit those empty __init__.py
files, while continuing to include any with contents!
Adapted from the docs
--skip-empty
skip any file with no executable statements--skip-covered
skip any file with 100% coveragehttps://coverage.readthedocs.io/en/stable/cmd.html#coverage-summary
This has been available since coverage 5.0 via GitHub PR 864
To exclude all empty files, i.e. files without any statements, and thus 100% coverage you can use:
$ coverage report | grep -v " 0 0 0 0 100%"
Unfortunately, this does not exclude those files from the coverage html report and is more cumbersome than a simple option.
© 2022 - 2024 — McMap. All rights reserved.
.coveragerc
file, where you add all empty files to[run] omit
.. – Beluga