From 7d211e8a724bacacdd5747adc55805bb2bb43c67 Mon Sep 17 00:00:00 2001 From: Flavio Oliva Date: Mon, 30 Nov 2026 20:44:55 +0000 Subject: [PATCH] test(errors): check error classes defined outside errors.py when run alone (#1663) The defaults test walks GFlowError.__subclasses__(), which sees a class only once its module is imported. CharacterNotFoundError and RelaunchFailed live outside errors.py, so the file run on its own left them unchecked. Import every module that subclasses an errors.py class before the walk. --- CHANGELOG.md | 1 + tests/test_problem_details_extensions.py | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a54715a9..55a82f05e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Tests +- `tests/test_problem_details_extensions.py` imports every module that subclasses an `errors.py` class before it checks each error class's declared defaults, so `CharacterNotFoundError` and `RelaunchFailed` are checked even when the file runs alone ([#1663](https://github.com/ffroliva/gflow-cli/issues/1663)). - The browser-launch and cookie diagnostic events of `FlowApiClient` (`client.persistent_context_launch`, `client.context_cookie_state`, `client.preread_flow_cookies`, `client.context_cookies_seeded`, `client.har_capture_enabled` and their failure events) have their event names and the field keys and values that triage reads pinned by tests, and the remaining mutmut survivors in the client lifecycle are recorded as equivalent in `docs/DEVELOPMENT.md` (#1266). ## [0.110.0] — 2026-11-30 diff --git a/tests/test_problem_details_extensions.py b/tests/test_problem_details_extensions.py index 489ee8fc6..eab2a4147 100644 --- a/tests/test_problem_details_extensions.py +++ b/tests/test_problem_details_extensions.py @@ -9,6 +9,7 @@ from __future__ import annotations +import importlib import re from pathlib import Path from types import SimpleNamespace @@ -36,7 +37,22 @@ _DOC = Path(__file__).resolve().parents[1] / "docs" / "ERRORS.md" +_SRC = Path(__file__).resolve().parents[1] / "src" / "gflow_cli" + + +def _import_error_modules() -> None: + """Import every module that subclasses an ``errors.py`` class, so the walk below sees + those classes whatever other tests ran first (#1663).""" + names = set(re.findall(r"^class (\w+)\(", (_SRC / "errors.py").read_text("utf-8"), re.M)) + base = re.compile(r"^class \w+\((?:\w+\.)?(\w+)\)", re.M) + for path in _SRC.rglob("*.py"): + if path.name != "errors.py" and names & set(base.findall(path.read_text("utf-8"))): + parts = path.relative_to(_SRC).with_suffix("").parts + importlib.import_module(".".join(("gflow_cli", *parts)).removesuffix(".__init__")) + + def _all_error_classes() -> list[type[GFlowError]]: + _import_error_modules() seen: list[type[GFlowError]] = [] stack: list[type[GFlowError]] = [GFlowError] while stack: @@ -59,6 +75,12 @@ def _bare(cls: type[GFlowError], retryable: bool | None) -> GFlowError: _SUBCLASSES = [c for c in _all_error_classes() if c is not GFlowError] +def test_the_walk_sees_error_classes_defined_outside_errors_py() -> None: + # Run alone, the walk must still see them (#1663): no other test imports their modules. + names = {c.__name__ for c in _SUBCLASSES} + assert {"CharacterNotFoundError", "RelaunchFailed"} <= names + + @pytest.mark.parametrize("cls", _SUBCLASSES, ids=lambda c: c.__name__) def test_every_subclass_declares_its_own_defaults(cls: type[GFlowError]) -> None: # Own __dict__, not inheritance: a class added without a decision fails here.