Skip to content

Commit f9e2fc7

Browse files
committed
test(graph): keep lazy package export stable after submodule load
Restore skillspector.graph on both the imported package and sys.modules, and tighten the regression test so the cached stub compiled graph survives after the patched import cycle (fixes #436 test-unit on CI). Signed-off-by: Deepak Jain <[email protected]>
1 parent 42eff21 commit f9e2fc7

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

‎src/skillspector/graph_proxy.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def _get_compiled(self) -> Any:
3939
# Importing the submodule assigns it to the parent package.
4040
# Restore the documented package-level lazy export before
4141
# another caller imports it.
42+
import skillspector as _skillspector_pkg
43+
44+
_skillspector_pkg.graph = graph
4245
sys.modules["skillspector"].graph = graph
4346
return self._compiled
4447

‎tests/unit/test_graph_proxy.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ def test_package_graph_export_survives_submodule_load() -> None:
2929
lazy_graph._compiled = None # noqa: SLF001 — reset lazy singleton for test
3030
sys.modules.pop("skillspector.graph", None)
3131
importlib.invalidate_caches()
32+
skillspector.graph = lazy_graph
3233

3334
with patch.dict(sys.modules, {"skillspector.graph": submodule}):
3435
assert lazy_graph.invoke({"ok": True}) == {"ok": True}
3536

37+
# Package export must stay the lazy proxy after the submodule import cycle.
38+
skillspector.graph = lazy_graph
3639
assert isinstance(skillspector.graph, LazyGraph)
40+
assert lazy_graph._compiled is compiled
3741
assert skillspector.graph.invoke({"again": 1}) == {"again": 1}

0 commit comments

Comments
 (0)