Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

test: make doctor import failure assertion deterministic

Sameer6305556e786fd5c7
diff --git a/tests/test_cli_commands.py b/tests/test_cli_commands.py
index f2b626f7..3a6b91fd 100644
--- a/tests/test_cli_commands.py
+++ b/tests/test_cli_commands.py
@@ -1876,11 +1876,19 @@ class TestDoctorEmbeddings:
assert "Embeddings (sentence-transformers)" in checks
assert "Embeddings (fastembed)" in checks
- def test_import_failure_is_fail_status_with_hint(self, runner):
+ def test_import_failure_is_fail_status_with_hint(self, runner, monkeypatch):
+ # Force the 'import sentence_transformers' inside _embedding_backend to
+ # raise ImportError regardless of whether the package is installed on
+ # this machine. Setting a module entry to None is the standard Python
+ # mechanism: any subsequent 'import <name>' raises
+ # "import of <name> halted; None in sys.modules".
+ monkeypatch.setitem(
+ __import__("sys").modules, "sentence_transformers", None
+ )
checks = self._doctor_checks(runner)
st = checks["Embeddings (sentence-transformers)"]
- if st["status"] == "fail":
- assert st["hint"] == "pip install sentence-transformers"
+ assert st["status"] == "fail"
+ assert st["hint"] == "pip install sentence-transformers"
def test_deep_probe_detects_fallback_active(self, runner, monkeypatch):
self._with_fake_st(monkeypatch)