Skip to content

Coverage misses import-time lines: run pytest under coverage instead of pytest-cov #46

Description

@CaptainDriftwood

Problem

Coverage numbers are systematically deflated and three modules are excluded outright. Root cause: the icap package registers a pytest11 entry-point plugin, so pytest imports the whole package during plugin loading, before pytest-cov starts measuring. Every module-level line (imports, def/class statements, decorators, constants) is recorded as missed, and the config works around it by omitting __init__.py, exception.py, and _protocol.py ('executed before coverage starts').

The _protocol.py omit is now costly: since the shared-logic refactor it contains core parsing/validation (parse_chunk_size, parse_response_headers, _validate_service_name, prepare_preview_data) with zero coverage visibility.

Validated fix

Run pytest under coverage so measurement starts at interpreter level, before plugin loading:

coverage run -m pytest -m 'not integration'
coverage combine
coverage report / coverage xml

Measured on the same test run (unit tests only), before → after:

Module pytest-cov coverage run
icap.py 85% 92%
response.py 61% 93%
__init__.py omitted 100%
exception.py omitted 100%
_protocol.py omitted 98%

Remaining missing lines after the switch are genuine behavioral gaps (tracked separately), not import-time noise.

Changes

  • noxfile.py coverage sessions: replace pytest --cov=src/icap with coverage run -m pytest + coverage combine + coverage report --show-missing + coverage xml (config already has parallel = true); drop the pytest-cov dep from those sessions.
  • Remove the omit entries for __init__.py, exception.py, _protocol.py in pyproject.toml.
  • If coverage runs ever adopt xdist (-n auto): add patch = ["subprocess"] to [tool.coverage.run] (requires coverage >= 7.10; lockfile has 7.13.4) so worker processes are measured from interpreter startup too.
  • Consider setting fail_under (~85%) once the numbers are trustworthy.
  • Update the CI coverage job if it invokes pytest-cov directly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions