From 778da930cbfb83af80fc7e6d1674ccc8f4dc01a8 Mon Sep 17 00:00:00 2001 From: Codex Date: Sun, 30 Aug 2026 18:51:52 +0300 Subject: [PATCH] fix: the quality test no longer stubs packages in sys.modules (#42) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Same defect class as #389: _const() planted bare ModuleType stand-ins for custom_components(.houseplan) and never removed them, so the HA harness running later in the same pytest process saw a package without async_setup — 85 test_ha_* failures with 'No setup or config entry setup function defined'. const.py imports nothing, so the loader needs no package context at all: load it by file path under a standalone module name and leave sys.modules untouched (verified: no custom_components* keys after _const()). User-Visible: no Issue: #42 --- tests_backend/test_backend_quality.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/tests_backend/test_backend_quality.py b/tests_backend/test_backend_quality.py index fe1f9269..6a06d910 100644 --- a/tests_backend/test_backend_quality.py +++ b/tests_backend/test_backend_quality.py @@ -4,27 +4,25 @@ Pure tests: no homeassistant import, runnable in any environment. """ from __future__ import annotations +import importlib.util import json import re -import sys -import types -import importlib.util from pathlib import Path REPO = Path(__file__).resolve().parent.parent BACKEND = REPO / "custom_components" / "houseplan" +# Loading const.py by file path with a standalone module name deliberately +# avoids stubbing "custom_components"/"custom_components.houseplan" in +# sys.modules: leftover ModuleType stand-ins poison the Home Assistant harness +# running later in the same pytest process — HA's loader then sees a package +# without async_setup and every harness test fails with "No setup or config +# entry setup function defined" (the exact #389 incident, caused by the schema +# dump script). const.py imports nothing, so no package context is needed. def _const(): - for name, path in ( - ("custom_components", REPO / "custom_components"), - ("custom_components.houseplan", BACKEND), - ): - module = types.ModuleType(name) - module.__path__ = [str(path)] - sys.modules[name] = module spec = importlib.util.spec_from_file_location( - "custom_components.houseplan.const", BACKEND / "const.py") + "houseplan_quality_const", BACKEND / "const.py") module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) return module