Fix #2694: Make chromadb an optional dependency to fix Windows installation issues

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-04-26 18:38:34 +00:00
parent 51eb5e9998
commit 8dd779371d
7 changed files with 319 additions and 159 deletions

View File

@@ -0,0 +1,25 @@
import unittest
from unittest.mock import patch, MagicMock
import sys
import pytest
from typing import Any, Dict, List, Optional
class TestOptionalChromadb(unittest.TestCase):
def test_rag_storage_import_error(self):
"""Test that RAGStorage raises an ImportError when chromadb is not installed."""
with patch.dict(sys.modules, {"chromadb": None}):
with pytest.raises(ImportError) as excinfo:
from crewai.memory.storage.rag_storage import RAGStorage
storage = RAGStorage(type="test")
assert "ChromaDB is not installed" in str(excinfo.value)
def test_knowledge_storage_import_error(self):
"""Test that KnowledgeStorage raises an ImportError when chromadb is not installed."""
with patch.dict(sys.modules, {"chromadb": None}):
with pytest.raises(ImportError) as excinfo:
from crewai.knowledge.storage.knowledge_storage import KnowledgeStorage
storage = KnowledgeStorage()
assert "ChromaDB is not installed" in str(excinfo.value)