Skip to content

Close coverage gap: deterministically cover stop_server() no-server branch (interface.py:285) #7

Description

@tschm

Problem

make test reports a single uncovered line: src/pycharting/api/interface.py:285 — the else: print("ⓘ No active server to stop") branch in stop_server(). Coverage sits at 99.80% (gate is 90%) solely because of this line.

A test for the branch already exists (tests/test_interface.py:168 test_stop_server_when_not_running), but it does not cover the line reliably.

Root cause

_active_server is a module-level global. The test calls stop_server() without resetting _active_server to None first. Under pytest-xdist parallelism, another test's running mock server leaks into the global, so the if _active_server and _active_server.is_running: branch is taken instead of the else. The test has no assertion on output, so it passes either way and the else branch goes uncovered.

Proposed fix

In tests/test_interface.py::test_stop_server_when_not_running, force the global to None before the call and assert on the message, e.g.:

def test_stop_server_when_not_running(self, monkeypatch, capsys):
    monkeypatch.setattr("pycharting.api.interface._active_server", None)
    stop_server()
    assert "No active server to stop" in capsys.readouterr().out

Acceptance criteria

  • make test reports src/pycharting/api/interface.py at 100% (no missing line 285) across repeated parallel runs.
  • The test asserts on the emitted "No active server to stop" message rather than merely not raising.

Subcategory: Test coverage & depth (9 → 10). Highest-leverage fix from the Rhiza quality assessment.

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