mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-27 17:18:13 +00:00
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:
@@ -1,5 +1,11 @@
|
||||
import pytest
|
||||
|
||||
chromadb_not_installed = False
|
||||
try:
|
||||
import chromadb
|
||||
except ImportError:
|
||||
chromadb_not_installed = True
|
||||
|
||||
from crewai.memory.long_term.long_term_memory import LongTermMemory
|
||||
from crewai.memory.long_term.long_term_memory_item import LongTermMemoryItem
|
||||
|
||||
@@ -10,6 +16,7 @@ def long_term_memory():
|
||||
return LongTermMemory()
|
||||
|
||||
|
||||
@pytest.mark.skipif(chromadb_not_installed, reason="ChromaDB is not installed")
|
||||
def test_save_and_search(long_term_memory):
|
||||
memory = LongTermMemoryItem(
|
||||
agent="test_agent",
|
||||
|
||||
@@ -2,6 +2,12 @@ from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
chromadb_not_installed = False
|
||||
try:
|
||||
import chromadb
|
||||
except ImportError:
|
||||
chromadb_not_installed = True
|
||||
|
||||
from crewai.agent import Agent
|
||||
from crewai.crew import Crew
|
||||
from crewai.memory.short_term.short_term_memory import ShortTermMemory
|
||||
@@ -28,6 +34,7 @@ def short_term_memory():
|
||||
return ShortTermMemory(crew=Crew(agents=[agent], tasks=[task]))
|
||||
|
||||
|
||||
@pytest.mark.skipif(chromadb_not_installed, reason="ChromaDB is not installed")
|
||||
def test_save_and_search(short_term_memory):
|
||||
memory = ShortTermMemoryItem(
|
||||
data="""test value test value test value test value test value test value
|
||||
|
||||
25
tests/storage/test_optional_chromadb.py
Normal file
25
tests/storage/test_optional_chromadb.py
Normal 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)
|
||||
Reference in New Issue
Block a user