From 556e786fd5c7c6cbe52d05cb714692b6725b7dfa Mon Sep 17 00:00:00 2001 From: Sameer6305 Date: Thu, 20 Aug 2026 15:49:46 +0530 Subject: [PATCH] test: make doctor import failure assertion deterministic --- tests/test_cli_commands.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 ' raises + # "import of 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)