Skip to content

Add pytest-cov coverage measurement and tests for log_utils.py#92

Merged
dgenio merged 2 commits intomainfrom
copilot/add-pytest-cov-coverage-measurement
Mar 9, 2026
Merged

Add pytest-cov coverage measurement and tests for log_utils.py#92
dgenio merged 2 commits intomainfrom
copilot/add-pytest-cov-coverage-measurement

Conversation

Copy link
Contributor

Copilot AI commented Mar 9, 2026

No coverage measurement existed in the test suite, and chainweaver/log_utils.py (83 lines, 4 public functions) had zero dedicated tests.

Changes

pyproject.toml

  • Added addopts to [tool.pytest.ini_options] to enforce coverage on every pytest run:
    addopts = "--cov=chainweaver --cov-report=term-missing --cov-fail-under=80"

tests/test_log_utils.py (new)

  • 20 tests across 4 classes covering every function in log_utils.py:
    • TestGetLogger — return type, name binding, identity semantics
    • TestLogStepStart — INFO level, step index, tool name, inputs, START marker
    • TestLogStepEnd — INFO level, step index, tool name, outputs, END marker
    • TestLogStepError — ERROR level, step index, tool name, exception type/message, ERROR marker
  • Uses caplog fixture for log capture; consistent with existing test conventions

Result

Full suite: 66 tests, 98.6% coverage — threshold of 80% is met with significant headroom.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add pytest-cov coverage measurement and tests for log_utils.py</issue_title>
<issue_description>## Category
code-quality | Priority: P2 | Effort: S (1–2 days)

Context

The test suite (503 lines in test_flow_execution.py + 120 lines in test_registry.py) appears thorough but there's no coverage measurement to verify which lines and branches are actually tested. Additionally, chainweaver/log_utils.py has zero tests.

Evidence:

  • No pytest-cov in dev dependencies
  • ci.yml runs pytest tests/ -v with no coverage flags
  • chainweaver/log_utils.py (83 lines) — get_logger(), log_step_start(), log_step_end(), log_step_error() have no dedicated tests
  • No coverage reporting or threshold enforcement

What to do

Add pytest-cov for coverage measurement, set a coverage threshold in CI, and add missing tests for log_utils.py.

Implementation steps

  1. Add pytest-cov to dev dependencies in pyproject.toml:

    [project.optional-dependencies]
    dev = [
        "pytest>=7.0",
        "pytest-cov>=4.0",
    ]
  2. Update pytest config in pyproject.toml:

    [tool.pytest.ini_options]
    testpaths = ["tests"]
    python_files = ["test_*.py"]
    python_classes = ["Test*"]
    python_functions = ["test_*"]
    addopts = "--cov=chainweaver --cov-report=term-missing --cov-fail-under=80"
  3. Update CI to show coverage in test output:
    The addopts in pyproject.toml will automatically apply. No changes needed to CI commands unless you want a separate coverage artifact.

  4. Add tests for log_utils.py — create tests/test_log_utils.py:

    • Test get_logger() returns a logging.Logger with correct name
    • Test log_step_start() emits INFO log with correct format
    • Test log_step_end() emits INFO log with correct format
    • Test log_step_error() emits ERROR log with correct format
    • Use caplog pytest fixture to capture log output

Files to modify

  • pyproject.toml — update dev deps + pytest config
  • tests/test_log_utils.py — new test file

Definition of Done

  • pytest-cov in dev dependencies
  • --cov=chainweaver --cov-report=term-missing --cov-fail-under=80 in pytest addopts
  • tests/test_log_utils.py created with tests for all 4 functions in log_utils.py
  • Coverage threshold passes (≥80%)
  • CI is green

Dependencies

None — but benefits from #38 (Ruff) and #39 (mypy) being done first so new test code is also linted/typed.

Execution order

Issue 6 of 7 — completes the testing infrastructure.


Related: #38 (Ruff), #39 (mypy) | Part of the P4 initiative to improve both AI-agent readiness and SWE best practices.</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: dgenio <12731907+dgenio@users.noreply.github.com>
Copilot AI changed the title [WIP] Add pytest-cov coverage measurement and tests for log_utils.py Add pytest-cov coverage measurement and tests for log_utils.py Mar 9, 2026
@dgenio dgenio requested a review from Copilot March 9, 2026 05:55
@dgenio dgenio marked this pull request as ready for review March 9, 2026 05:56
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens the project’s testing discipline by enabling automatic coverage measurement on every pytest run and adding dedicated unit tests for chainweaver.log_utils (the structured step-logging helpers used by the executor).

Changes:

  • Enforce coverage measurement + minimum threshold via pytest config (--cov=chainweaver --cov-report=term-missing --cov-fail-under=80).
  • Add a new tests/test_log_utils.py suite that exercises get_logger, log_step_start, log_step_end, and log_step_error using caplog.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pyproject.toml Adds pytest addopts so coverage is always collected and a minimum threshold is enforced.
tests/test_log_utils.py Adds targeted tests validating that log utilities emit correctly leveled, structured messages.

You can also share your feedback on Copilot code review. Take the survey.

@dgenio dgenio merged commit 35503d6 into main Mar 9, 2026
8 checks passed
@dgenio dgenio deleted the copilot/add-pytest-cov-coverage-measurement branch March 9, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pytest-cov coverage measurement and tests for log_utils.py

3 participants