coveragepy
coveragepy copied to clipboard
report specifies a missing range where separate lines are expected
Describe the bug
coverage report shows unexpected range including covered and excluded lines
To Reproduce
$ rm -rf venv .coverage
$ python3.11 -m venv venv
$ venv/bin/python --version --version
Python 3.11.2 (main, Mar 5 2023, 21:14:41) [GCC 11.3.0]
$ venv/bin/python -m pip install git+https://github.com/nedbat/coveragepy@a3d915e6a5552dcc96601dd7ee75db809e364e33
Collecting git+https://github.com/nedbat/coveragepy@a3d915e6a5552dcc96601dd7ee75db809e364e33
Cloning https://github.com/nedbat/coveragepy (to revision a3d915e6a5552dcc96601dd7ee75db809e364e33) to /tmp/pip-req-build-5mtjtvaa
Running command git clone --filter=blob:none --quiet https://github.com/nedbat/coveragepy /tmp/pip-req-build-5mtjtvaa
Running command git rev-parse -q --verify 'sha^a3d915e6a5552dcc96601dd7ee75db809e364e33'
Running command git fetch -q https://github.com/nedbat/coveragepy a3d915e6a5552dcc96601dd7ee75db809e364e33
Resolved https://github.com/nedbat/coveragepy to commit a3d915e6a5552dcc96601dd7ee75db809e364e33
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: coverage
Building wheel for coverage (pyproject.toml) ... done
Created wheel for coverage: filename=coverage-7.3.3a0.dev1-cp311-cp311-linux_x86_64.whl size=230523 sha256=7716fa9e6bafbb85946bd0d3313513e302c009ddb7a40383213492bb41f99db7
Stored in directory: /home/altendky/.cache/pip/wheels/92/f7/bb/de3a599f4d9666983fb530d6fab1e8576ed43bafa869c2c58f
Successfully built coverage
Installing collected packages: coverage
Successfully installed coverage-7.3.3a0.dev1
[notice] A new release of pip available: 22.3.1 -> 23.3
[notice] To update, run: /home/altendky/tmp/venv/bin/python -m pip install --upgrade pip
$ venv/bin/python -m pip freeze --all
coverage @ git+https://github.com/nedbat/coveragepy@a3d915e6a5552dcc96601dd7ee75db809e364e33
pip==22.3.1
setuptools==65.5.0
$ cat --number x.py
1 from __future__ import annotations
2
3
4 def a(first_fixture_name: FixtureType) -> None:
5 print()
6
7 def b(
8 first_fixture_name: FixtureType,
9 ) -> None:
10 print()
11
12 def c(another_fixture_name: FixtureType) -> None: # pragma: no cover
13 print()
14
15 def d(
16 another_fixture_name: FixtureType, # pragma: no cover
17 ) -> None:
18 print()
19
20 print("the end")
$ cat .coveragerc
[report]
exclude_also =
first_fixture_name[^)]*\)[^:]*:
$ venv/bin/python x.py
the end
$ venv/bin/coverage run --rcfile .coveragerc x.py
the end
$ venv/bin/coverage report --rcfile .coveragerc --show-missing
Name Stmts Miss Cover Missing
-------------------------------------
x.py 5 2 60% 10-18
-------------------------------------
TOTAL 5 2 60%
$ venv/bin/coverage json --rcfile .coveragerc --pretty-print -o -
{
"meta": {
"version": "7.3.3a0.dev1",
"timestamp": "2023-10-18T08:25:04.198309",
"branch_coverage": false,
"show_contexts": false
},
"files": {
"x.py": {
"executed_lines": [
1,
4,
7,
12,
15,
20
],
"summary": {
"covered_lines": 3,
"num_statements": 5,
"percent_covered": 60.0,
"percent_covered_display": "60",
"missing_lines": 2,
"excluded_lines": 5
},
"missing_lines": [
10,
18
],
"excluded_lines": [
4,
5,
12,
13,
15
]
}
},
"totals": {
"covered_lines": 3,
"num_statements": 5,
"percent_covered": 60.0,
"percent_covered_display": "60",
"missing_lines": 2,
"excluded_lines": 5
}
}
$ venv/bin/coverage debug sys
-- sys -------------------------------------------------------
coverage_version: 7.3.3a0.dev1
coverage_module: /home/altendky/tmp/venv/lib/python3.11/site-packages/coverage/__init__.py
tracer: -none-
CTracer: available
plugins.file_tracers: -none-
plugins.configurers: -none-
plugins.context_switchers: -none-
configs_attempted: .coveragerc
configs_read: /home/altendky/tmp/.coveragerc
config_file: /home/altendky/tmp/.coveragerc
config_contents: b'[report]\nexclude_also =\n first_fixture_name[^)]*\\)[^:]*:\n'
data_file: -none-
python: 3.11.2 (main, Mar 5 2023, 21:14:41) [GCC 11.3.0]
platform: Linux-6.2.0-34-generic-x86_64-with-glibc2.35
implementation: CPython
executable: /home/altendky/tmp/venv/bin/python
def_encoding: utf-8
fs_encoding: utf-8
pid: 9733
cwd: /home/altendky/tmp
path: /home/altendky/tmp/venv/bin
/home/altendky/.pyenv/versions/3.11.2/lib/python311.zip
/home/altendky/.pyenv/versions/3.11.2/lib/python3.11
/home/altendky/.pyenv/versions/3.11.2/lib/python3.11/lib-dynload
/home/altendky/tmp/venv/lib/python3.11/site-packages
environment: HOME = /home/altendky
PYENV_ROOT = /home/altendky/.pyenv
PYTHONDONTWRITEBYTECODE = 1
PYTHON_CONFIGURE_OPTS = --enable-shared
command_line: venv/bin/coverage debug sys
sqlite3_sqlite_version: 3.37.2
sqlite3_temp_store: 0
sqlite3_compile_options: ATOMIC_INTRINSICS=1, COMPILER=gcc-11.3.0, DEFAULT_AUTOVACUUM,
DEFAULT_CACHE_SIZE=-2000, DEFAULT_FILE_FORMAT=4,
DEFAULT_JOURNAL_SIZE_LIMIT=-1, DEFAULT_MMAP_SIZE=0, DEFAULT_PAGE_SIZE=4096,
DEFAULT_PCACHE_INITSZ=20, DEFAULT_RECURSIVE_TRIGGERS,
DEFAULT_SECTOR_SIZE=4096, DEFAULT_SYNCHRONOUS=2,
DEFAULT_WAL_AUTOCHECKPOINT=1000, DEFAULT_WAL_SYNCHRONOUS=2,
DEFAULT_WORKER_THREADS=0, ENABLE_COLUMN_METADATA, ENABLE_DBSTAT_VTAB,
ENABLE_FTS3, ENABLE_FTS3_PARENTHESIS, ENABLE_FTS3_TOKENIZER, ENABLE_FTS4,
ENABLE_FTS5, ENABLE_JSON1, ENABLE_LOAD_EXTENSION, ENABLE_MATH_FUNCTIONS,
ENABLE_PREUPDATE_HOOK, ENABLE_RTREE, ENABLE_SESSION, ENABLE_STMTVTAB,
ENABLE_UNLOCK_NOTIFY, ENABLE_UPDATE_DELETE_LIMIT, HAVE_ISNAN,
LIKE_DOESNT_MATCH_BLOBS, MALLOC_SOFT_LIMIT=1024, MAX_ATTACHED=10,
MAX_COLUMN=2000, MAX_COMPOUND_SELECT=500, MAX_DEFAULT_PAGE_SIZE=32768,
MAX_EXPR_DEPTH=1000, MAX_FUNCTION_ARG=127, MAX_LENGTH=1000000000,
MAX_LIKE_PATTERN_LENGTH=50000, MAX_MMAP_SIZE=0x7fff0000,
MAX_PAGE_COUNT=1073741823, MAX_PAGE_SIZE=65536, MAX_SCHEMA_RETRY=25,
MAX_SQL_LENGTH=1000000000, MAX_TRIGGER_DEPTH=1000,
MAX_VARIABLE_NUMBER=250000, MAX_VDBE_OP=250000000, MAX_WORKER_THREADS=8,
MUTEX_PTHREADS, OMIT_LOOKASIDE, SECURE_DELETE, SOUNDEX, SYSTEM_MALLOC,
TEMP_STORE=1, THREADSAFE=1, USE_URI
Expected behavior
The report output would be the separate lines 10, 18 not the range 10-18.
Additional context
The big picture is that I am exploring ways to easily exclude all tests using a certain fixture since they are run separately without coverage measurement. This was an observation along the way.
This does look odd, and I guess could be improved. The logic is that between lines 10 and 18, there are no lines that could be executed that were executed, so the range is expressed as 10-18. This is so that comments and blank lines won't interrupt a range. Perhaps excluded lines should be considered differently.