-
-
Couldn't load subscription status.
- Fork 459
Description
Describe the bug
exclude_lines in .coveragerc are not being respected for excluding import statements and pragma: no cover.
To Reproduce
How can we reproduce the problem? Please be specific. Don't link to a failing CI job. Answer the questions below:
- What version of Python are you using? 3.8.17
- What version of coverage.py shows the problem?
coverage debug sys -- sys ------------------------------------------------------- coverage_version: 7.2.1 coverage_module: /opt/homebrew/lib/python3.8/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: /Users/jacqueline.lee/jkl/prototype/.coveragerc config_file: /Users/jacqueline.lee/jkl/prototype/.coveragerc config_contents: b'[run]\nrelative_files = True\n# omit =\n# # omit anything in a .local directory anywhere\n# */.local/*\n# # omit everything in /usr\n# /usr/*\n# /opt/**/*.py\n\nomit=*/site-packages/*,*/tests/*,*/.eggs/*\n\nsource =\n /Users/jacqueline.lee/jkl/prototype/*\n\n\n[report]\n# number of digits after the decimal point to display for reported coverage percentages\nprecision = 2\n\nexclude_lines =\n # skip any line with a `pass` (such as may be used for @abstractmethod or @suffixed_method)\n pass\n # skip any line with import\n import\n\n # standard pragma\n pragma: no cover\n #\\s*(pragma|PRAGMA)[:\\s]?\\s*(no|NO)\\s*(branch|BRANCH)\n\n # skip blocks reserved for type checking\n if TYPE_CHECKING:\n\n\n# Any line of your source code containing a match for one of these regexes is excluded from being reported as missing.\n# You can exclude lines introducing blocks, and the entire block is excluded. If you exclude a def line or decorator line, the entire function is excluded.\n# https://coverage.readthedocs.io/en/latest/excluding.html#excluding\n\nskip_empty = True' data_file: -none- python: 3.8.17 (default, Jun 6 2023, 17:41:59) [Clang 14.0.3 (clang-1403.0.22.14.1)] platform: macOS-13.5.2-arm64-arm-64bit implementation: CPython executable: /opt/homebrew/opt/python@3.8/bin/python3.8 def_encoding: utf-8 fs_encoding: utf-8 pid: 71618 cwd: /Users/jacqueline.lee/jkl/prototype path: /opt/homebrew/bin /opt/homebrew/Cellar/python@3.8/3.8.17/Frameworks/Python.framework/Versions/3.8/lib/python38.zip /opt/homebrew/Cellar/python@3.8/3.8.17/Frameworks/Python.framework/Versions/3.8/lib/python3.8 /opt/homebrew/Cellar/python@3.8/3.8.17/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload /opt/homebrew/lib/python3.8/site-packages environment: GRPC_PYTHON_BUILD_SYSTEM_OPENSSL = 1 GRPC_PYTHON_BUILD_SYSTEM_ZLIB = 1 HOME = /Users/jacqueline.lee PYENV_SHELL = bash PYENV_VIRTUALENVWRAPPER_PREFER_PYVENV = true PYENV_VIRTUALENVWRAPPER_PYENV_VERSION = 3.6.15 PYENV_VIRTUALENV_INIT = 1 VIRTUALENVWRAPPER_PYTHON = /Users/jacqueline.lee/.pyenv/versions/3.6.15/bin/python command_line: /opt/homebrew/bin/coverage debug sys sqlite3_sqlite_version: 3.43.1 sqlite3_temp_store: 0 sqlite3_compile_options: ATOMIC_INTRINSICS=1, COMPILER=clang-14.0.3, 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_API_ARMOR, ENABLE_COLUMN_METADATA, ENABLE_DBSTAT_VTAB, ENABLE_FTS3, ENABLE_FTS3_PARENTHESIS, ENABLE_FTS4, ENABLE_FTS5, ENABLE_GEOPOLY, ENABLE_MATH_FUNCTIONS, ENABLE_MEMORY_MANAGEMENT, ENABLE_PREUPDATE_HOOK, ENABLE_RTREE, ENABLE_SESSION, ENABLE_STAT4, ENABLE_UNLOCK_NOTIFY, MALLOC_SOFT_LIMIT=1024, MAX_ATTACHED=10, MAX_COLUMN=2000, MAX_COMPOUND_SELECT=500, MAX_DEFAULT_PAGE_SIZE=8192, 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_SQL_LENGTH=1000000000, MAX_TRIGGER_DEPTH=1000, MAX_VARIABLE_NUMBER=250000, MAX_VDBE_OP=250000000, MAX_WORKER_THREADS=8, MUTEX_PTHREADS, SYSTEM_MALLOC, TEMP_STORE=1, THREADSAFE=1, USE_URI - What versions of what packages do you have installed?
pip freeze black==22.8.0 bump2version==1.0.1 bumpversion==0.6.0 click==8.0.4 dataclasses==0.8 distlib==0.3.6 filelock==3.4.1 importlib-metadata==4.8.3 importlib-resources==5.4.0 isort==5.10.1 lxml==4.9.2 mypy==0.971 mypy-extensions==1.0.0 packaging==21.3 pathspec==0.9.0 pbr==5.11.0 pep517==0.13.0 pip-tools==6.4.0 platformdirs==2.4.0 plotly==5.15.0 py-spy==0.3.14 pyparsing==3.1.0 PyYAML==6.0 sphinx2rst==1.1.0 stevedore==3.5.2 tenacity==8.2.2 tokei-pie==1.2.0 tomli==1.2.3 typed-ast==1.5.4 typing_extensions==4.1.1 virtualenv==20.16.6 virtualenv-clone==0.5.7 virtualenvwrapper==4.8.4 zipp==3.6.0 -
What code shows the problem?
See main branch on https://github.com/tingilee/coverage-prototype/ -
What commands should we run to reproduce the problem?
$ git clone git@github.com:tingilee/coverage-prototype.git
$ coverage run --debug=config --rcfile=/Users/jacqueline.lee/jkl/prototype/.coveragerc --append --branch -m pytest ~/jkl/prototype/ && coverage lcov -o /tmp/output_coverage_jkl
Verify the debug output contains the custom config.
$ genhtml --output ~/jkl/genhtml /tmp/output_coverage_jkl
Then, open the generated~/jkl/genhtml/index.htmland see the attached screenshot for result.
Expected behavior
Line 1 & 2 should be excluded without reporting hit or missing, to respect the configurations in .coveragerc.
https://github.com/tingilee/coverage-prototype/blob/main/test_jkl.py#L1-L2
Here's .coveragerc to exclude lines of import statements and pragma: no cover.
https://github.com/tingilee/coverage-prototype/blob/main/.coveragerc#L20-L27
