From a31ce9bd9e82279ff806c6432fcfe6914e2be1aa Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 13 Oct 2026 11:23:13 -1000 Subject: [PATCH] Drop the components package too so the re-import is real --- .../benchmarks/python/test_component_import_bench.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/benchmarks/python/test_component_import_bench.py b/tests/benchmarks/python/test_component_import_bench.py index e1dd202c2aa..348bb036988 100644 --- a/tests/benchmarks/python/test_component_import_bench.py +++ b/tests/benchmarks/python/test_component_import_bench.py @@ -33,11 +33,18 @@ import esphome.codegen # noqa: E402, F401 import esphome.config_validation # noqa: E402, F401 COMPONENTS = ("binary_sensor", "sensor", "logger") -COMPONENT_PREFIX = "esphome.components." +COMPONENT_PACKAGE = "esphome.components" +COMPONENT_PREFIX = COMPONENT_PACKAGE + "." def _component_modules() -> dict[str, object]: - return {n: m for n, m in sys.modules.items() if n.startswith(COMPONENT_PREFIX)} + # The package itself goes too: ``from esphome.components import x`` is + # answered from its attributes, so a stale package would hide the import. + return { + n: m + for n, m in sys.modules.items() + if n == COMPONENT_PACKAGE or n.startswith(COMPONENT_PREFIX) + } def _forget_component_modules() -> None: