Skip the coverage bar on -k subset runs
Some checks are pending
md-naming / markdown naming convention (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (flutter, flutter-analyze, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Waiting to run
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint,flutter-analyze,dependency-freshness) (push) Waiting to run
Tests / test (push) Waiting to run
Tests / lock-popup-safety (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (0) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (1) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (2) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (3) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (4) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (5) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (6) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (7) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (8) (push) Waiting to run
Tests / flutter test (shard ${{ matrix.shard }}) (9) (push) Waiting to run
Tests / flutter-coverage (push) Blocked by required conditions
Tests / web-coverage (push) Waiting to run
repo-contract / repo contract (push) Waiting to run

pytest -q -k <name> (the board's done_check form) exited 1 on green
tests: fail_under = 100 judged a handful of tests against the whole
package. A pytest_sessionstart plugin clears pytest-cov's fail_under
when a keyword is given; whole-suite runs (commit gate, full_gate.sh,
CI) select none and keep the bar.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-11-23 13:49:14 +01:00
parent c7a7593a55
commit a8c6177012
3 changed files with 71 additions and 0 deletions

View File

@ -267,6 +267,9 @@ addopts = [
# repo's 400-line-per-file cap) -- see its own docstring.
"-p",
"screen_locker.tests.test_sync_fixtures",
# A `-k` run is a subset: only whole-suite runs need fail_under = 100.
"-p",
"screen_locker.tests._subset_coverage",
]
filterwarnings = [
"error",

View File

@ -0,0 +1,28 @@
"""Hold only whole-suite runs to pyproject's ``fail_under = 100``.
A ``-k`` run selects a handful of tests, so its total coverage is always far
below 100% and pytest-cov turned every green ``pytest -q -k <name>`` (the
board's done_check form) into exit 1. The commit gate, the nightly
``full_gate.sh`` and CI select no keyword, so they keep the bar. Path-selected
partial runs (``test_changed.sh``, ``push_gate.sh``) pass ``--no-cov``
themselves and are untouched.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
import pytest
def pytest_sessionstart(session: pytest.Session) -> None:
"""Drop the coverage bar for a ``-k`` keyword-selected run.
pytest-cov copies ``fail_under`` into its options when coverage starts
(before this hook) and checks it at the end; ``None`` skips the check.
"""
config = session.config
cov = config.pluginmanager.getplugin("_cov")
if cov is not None and config.option.keyword:
cov.options.cov_fail_under = None

View File

@ -0,0 +1,40 @@
"""A ``-k`` run is a subset: the 100% coverage bar is for whole-suite runs.
The board's done_checks are ``pytest -q -k <name>``; with ``fail_under = 100``
in pyproject every one of them exited 1 on green tests (2026-11-23).
"""
from __future__ import annotations
from types import SimpleNamespace
from screen_locker.tests import _subset_coverage
def _config(keyword: str, fail_under: float | None) -> SimpleNamespace:
cov = SimpleNamespace(options=SimpleNamespace(cov_fail_under=fail_under))
manager = SimpleNamespace(getplugin=lambda name: cov if name == "_cov" else None)
return SimpleNamespace(
option=SimpleNamespace(keyword=keyword), pluginmanager=manager
)
def test_keyword_run_drops_the_coverage_bar() -> None:
"""``-k name`` selects a subset: its coverage is not held to fail_under."""
config = _config("preview_review_sequence", 100)
_subset_coverage.pytest_sessionstart(SimpleNamespace(config=config))
assert config.pluginmanager.getplugin("_cov").options.cov_fail_under is None
def test_whole_suite_keeps_the_coverage_bar() -> None:
"""No ``-k``: the commit gate's full run still needs 100%."""
config = _config("", 100)
_subset_coverage.pytest_sessionstart(SimpleNamespace(config=config))
assert config.pluginmanager.getplugin("_cov").options.cov_fail_under == 100
def test_no_coverage_plugin_is_left_alone() -> None:
"""``--no-cov`` or ``-p no:cov``: nothing to relax, no crash."""
manager = SimpleNamespace(getplugin=lambda _name: None)
config = SimpleNamespace(option=SimpleNamespace(keyword="x"), pluginmanager=manager)
_subset_coverage.pytest_sessionstart(SimpleNamespace(config=config))