Update memory tests to handle optional ChromaDB dependency

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-05-30 09:37:44 +00:00
parent a0057afe45
commit ea5f6b592c
3 changed files with 96 additions and 0 deletions

View File

@@ -2385,6 +2385,16 @@ def test_multiple_conditional_tasks(researcher, writer):
def test_using_contextual_memory():
from unittest.mock import patch
# Check if ChromaDB is available
try:
import chromadb
HAS_CHROMADB = True
except ImportError:
HAS_CHROMADB = False
if not HAS_CHROMADB:
pytest.skip("ChromaDB is required for this test")
math_researcher = Agent(
role="Researcher",
goal="You research about math.",
@@ -2413,6 +2423,16 @@ def test_using_contextual_memory():
def test_using_contextual_memory_with_long_term_memory():
from unittest.mock import patch
# Check if ChromaDB is available
try:
import chromadb
HAS_CHROMADB = True
except ImportError:
HAS_CHROMADB = False
if not HAS_CHROMADB:
pytest.skip("ChromaDB is required for this test")
math_researcher = Agent(
role="Researcher",
goal="You research about math.",
@@ -2442,6 +2462,16 @@ def test_using_contextual_memory_with_long_term_memory():
def test_warning_long_term_memory_without_entity_memory():
from unittest.mock import patch
# Check if ChromaDB is available
try:
import chromadb
HAS_CHROMADB = True
except ImportError:
HAS_CHROMADB = False
if not HAS_CHROMADB:
pytest.skip("ChromaDB is required for this test")
math_researcher = Agent(
role="Researcher",
goal="You research about math.",
@@ -2479,6 +2509,16 @@ def test_warning_long_term_memory_without_entity_memory():
def test_long_term_memory_with_memory_flag():
from unittest.mock import patch
# Check if ChromaDB is available
try:
import chromadb
HAS_CHROMADB = True
except ImportError:
HAS_CHROMADB = False
if not HAS_CHROMADB:
pytest.skip("ChromaDB is required for this test")
math_researcher = Agent(
role="Researcher",
goal="You research about math.",
@@ -2514,6 +2554,16 @@ def test_long_term_memory_with_memory_flag():
def test_using_contextual_memory_with_short_term_memory():
from unittest.mock import patch
# Check if ChromaDB is available
try:
import chromadb
HAS_CHROMADB = True
except ImportError:
HAS_CHROMADB = False
if not HAS_CHROMADB:
pytest.skip("ChromaDB is required for this test")
math_researcher = Agent(
role="Researcher",
goal="You research about math.",
@@ -2543,6 +2593,16 @@ def test_using_contextual_memory_with_short_term_memory():
def test_disabled_memory_using_contextual_memory():
from unittest.mock import patch
# Check if ChromaDB is available
try:
import chromadb
HAS_CHROMADB = True
except ImportError:
HAS_CHROMADB = False
if not HAS_CHROMADB:
pytest.skip("ChromaDB is required for this test")
math_researcher = Agent(
role="Researcher",
goal="You research about math.",

View File

@@ -7,10 +7,28 @@ from crewai.memory.long_term.long_term_memory_item import LongTermMemoryItem
@pytest.fixture
def long_term_memory():
"""Fixture to create a LongTermMemory instance"""
try:
import chromadb
HAS_CHROMADB = True
except ImportError:
HAS_CHROMADB = False
if not HAS_CHROMADB:
pytest.skip("ChromaDB is required for this test")
return LongTermMemory()
def test_save_and_search(long_term_memory):
try:
import chromadb
HAS_CHROMADB = True
except ImportError:
HAS_CHROMADB = False
if not HAS_CHROMADB:
pytest.skip("ChromaDB is required for this test")
memory = LongTermMemoryItem(
agent="test_agent",
task="test_task",

View File

@@ -12,6 +12,15 @@ from crewai.task import Task
@pytest.fixture
def short_term_memory():
"""Fixture to create a ShortTermMemory instance"""
try:
import chromadb
HAS_CHROMADB = True
except ImportError:
HAS_CHROMADB = False
if not HAS_CHROMADB:
pytest.skip("ChromaDB is required for this test")
agent = Agent(
role="Researcher",
goal="Search relevant data and provide results",
@@ -29,6 +38,15 @@ def short_term_memory():
def test_save_and_search(short_term_memory):
try:
import chromadb
HAS_CHROMADB = True
except ImportError:
HAS_CHROMADB = False
if not HAS_CHROMADB:
pytest.skip("ChromaDB is required for this test")
memory = ShortTermMemoryItem(
data="""test value test value test value test value test value test value
test value test value test value test value test value test value