fix(tests): drop the speculative config-entries install guard — the scoped-stub teardowns already isolate per file; full suite green both variants (completes t30 G6)
This commit is contained in:
1 parent
e77bc12d81
commit
d004e73d99
2 files changed
+29
-7
No files matched your search
@@ -113,12 +113,6 @@ def install() -> None:
|
|||||||
"""Register the stub modules (idempotent)."""
|
"""Register the stub modules (idempotent)."""
|
||||||
if "homeassistant.components.media_player" in sys.modules:
|
if "homeassistant.components.media_player" in sys.modules:
|
||||||
return
|
return
|
||||||
# honor per-file flow stub versions already in place (e.g. the
|
|
||||||
# config-flow/pairing/protocol files) — the hub's base would strip the
|
|
||||||
# base plumbing the flow tests already installed (t30 leak).
|
|
||||||
ce = sys.modules.get("homeassistant.config_entries")
|
|
||||||
if ce is not None and hasattr(ce, "OptionsFlowWithReload"):
|
|
||||||
return
|
|
||||||
|
|
||||||
vol = types.ModuleType("voluptuous")
|
vol = types.ModuleType("voluptuous")
|
||||||
vol.Required = lambda key, default=None: key
|
vol.Required = lambda key, default=None: key
|
||||||
|
|||||||
+29
-1
@@ -13,17 +13,45 @@ from types import SimpleNamespace
|
|||||||
import entity_stublib
|
import entity_stublib
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
# Scoped-stub hygiene (mirrors tests/test_config_flow_pairing.py's
|
||||||
|
# scoped_stubs pattern): the config-flow files install their own stub faces
|
||||||
|
# and pop them per-test; test_init's runs must never leave a hub-stub set
|
||||||
|
# behind that a later file's loader would bind against.
|
||||||
|
_INIT_STUB_NAMES = (
|
||||||
|
"voluptuous",
|
||||||
|
"homeassistant",
|
||||||
|
"homeassistant.config_entries",
|
||||||
|
"homeassistant.core",
|
||||||
|
"homeassistant.helpers",
|
||||||
|
"homeassistant.helpers.entity_registry",
|
||||||
|
"homeassistant.helpers.device_registry",
|
||||||
|
"homeassistant.helpers.selector",
|
||||||
|
# the G8 lazy import in async_setup registers this platform module —
|
||||||
|
# without popping it the install() guard would skip the rebuild below
|
||||||
|
"homeassistant.components.media_player",
|
||||||
|
"nsh.helpers",
|
||||||
|
"nsh.config_flow",
|
||||||
|
"nsh.init",
|
||||||
|
"nsh.media_player",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
def _integration_module():
|
def _integration_module():
|
||||||
"""HA stubs + the integration __init__ module under nsh.init."""
|
"""HA stubs + the integration __init__ module under nsh.init."""
|
||||||
|
snapshot = {name: sys.modules.get(name) for name in _INIT_STUB_NAMES}
|
||||||
entity_stublib.install()
|
entity_stublib.install()
|
||||||
if "nsh.init" not in sys.modules:
|
if "nsh.init" not in sys.modules:
|
||||||
import conftest
|
import conftest
|
||||||
|
|
||||||
conftest._load_module("nsh.init", conftest._SHIELD_DIR / "__init__.py")
|
conftest._load_module("nsh.init", conftest._SHIELD_DIR / "__init__.py")
|
||||||
yield sys.modules["nsh.init"]
|
yield sys.modules["nsh.init"]
|
||||||
sys.modules.pop("nsh.init", None)
|
for name in _INIT_STUB_NAMES:
|
||||||
|
original = snapshot[name]
|
||||||
|
if original is None:
|
||||||
|
sys.modules.pop(name, None)
|
||||||
|
else:
|
||||||
|
sys.modules[name] = original
|
||||||
|
|
||||||
|
|
||||||
class _SeedEntriesStub:
|
class _SeedEntriesStub:
|
||||||
|
|||||||
Reference in new issue
Block a user