Summary
PR #3453 (test(slm): add unit tests for _ensure_local_node) is currently blocked because the test module stubs sys.modules for models but not for models.database, which is imported lazily inside the function body after the patch.dict context has exited.
Symptom
Tests fail with ImportError: No module named 'models.database' (or similar) when the code under test reaches the import statement inside the function.
Root Cause
The test uses:
with patch.dict(sys.modules, {"models": MagicMock()}):
...
Python resolves models.database as a separate sys.modules key. Since only "models" is stubbed, the submodule lookup fails when the function body imports models.database after the context manager scope.
Fix
Add the submodule to the stub dict:
with patch.dict(sys.modules, {
"models": MagicMock(),
"models.database": MagicMock(),
}):
...
Or use @patch.dict at class/method level so the stub persists for the full test body.
Labels
bug, test, low
Summary
PR #3453 (
test(slm): add unit tests for _ensure_local_node) is currently blocked because the test module stubssys.modulesformodelsbut not formodels.database, which is imported lazily inside the function body after thepatch.dictcontext has exited.Symptom
Tests fail with
ImportError: No module named 'models.database'(or similar) when the code under test reaches the import statement inside the function.Root Cause
The test uses:
Python resolves
models.databaseas a separatesys.moduleskey. Since only"models"is stubbed, the submodule lookup fails when the function body importsmodels.databaseafter the context manager scope.Fix
Add the submodule to the stub dict:
Or use
@patch.dictat class/method level so the stub persists for the full test body.Labels
bug, test, low