""" Test that the conftest gate catches missing required test dependencies and fails fast with a clear error message. This is a TDD test for the regression we just hit: sentence-transformers was in [project.optional-dependencies] but the test suite requires it unconditionally. A fresh `uv sync` (without --extra local-rag) produced a confusing "rag_status = error: ... Install with manual_slop[local-rag]" failure. The gate prevents this by failing at session start with the exact fix command. The check itself lives in conftest._check_required_test_dependencies() so it can be unit-tested here without a real conftest import. """ import sys import pytest def test_check_succeeds_when_deps_present() -> None: """ If sentence_transformers is importable, the gate is a no-op. This is the case for the test session that actually runs (sentence- transformers is installed via `uv sync --extra local-rag`). """ from tests.conftest import _check_required_test_dependencies _check_required_test_dependencies() def test_check_raises_on_missing_sentence_transformers(monkeypatch) -> None: """ Simulate sentence_transformers not being installed. The gate must raise pytest.UsageError with a clear, actionable error message that tells the user exactly how to fix the issue. """ # Block the import monkeypatch.setitem(sys.modules, "sentence_transformers", None) # Remove any cached successful import for mod_name in list(sys.modules): if mod_name == "sentence_transformers" or mod_name.startswith("sentence_transformers."): del sys.modules[mod_name] # Force ImportError on import import builtins original_import = builtins.__import__ def _blocking_import(name, *args, **kwargs): if name == "sentence_transformers" or name.startswith("sentence_transformers."): raise ImportError(f"No module named {name!r} (simulated)") return original_import(name, *args, **kwargs) monkeypatch.setattr(builtins, "__import__", _blocking_import) # Also need to invalidate the conftest's already-cached import from tests import conftest # Clear the module so it re-imports and the gate re-runs # Note: the conftest's _check function does its own import so this # is just a sanity check that the function is callable. from tests.conftest import _check_required_test_dependencies with pytest.raises(pytest.UsageError) as exc_info: _check_required_test_dependencies() msg = str(exc_info.value) assert "sentence-transformers" in msg assert "uv sync" in msg assert "local-rag" in msg