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

@@ -2384,6 +2384,16 @@ def test_multiple_conditional_tasks(researcher, writer):
@pytest.mark.vcr(filter_headers=["authorization"]) @pytest.mark.vcr(filter_headers=["authorization"])
def test_using_contextual_memory(): def test_using_contextual_memory():
from unittest.mock import patch 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( math_researcher = Agent(
role="Researcher", role="Researcher",
@@ -2412,6 +2422,16 @@ def test_using_contextual_memory():
@pytest.mark.vcr(filter_headers=["authorization"]) @pytest.mark.vcr(filter_headers=["authorization"])
def test_using_contextual_memory_with_long_term_memory(): def test_using_contextual_memory_with_long_term_memory():
from unittest.mock import patch 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( math_researcher = Agent(
role="Researcher", role="Researcher",
@@ -2441,6 +2461,16 @@ def test_using_contextual_memory_with_long_term_memory():
@pytest.mark.vcr(filter_headers=["authorization"]) @pytest.mark.vcr(filter_headers=["authorization"])
def test_warning_long_term_memory_without_entity_memory(): def test_warning_long_term_memory_without_entity_memory():
from unittest.mock import patch 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( math_researcher = Agent(
role="Researcher", role="Researcher",
@@ -2478,6 +2508,16 @@ def test_warning_long_term_memory_without_entity_memory():
@pytest.mark.vcr(filter_headers=["authorization"]) @pytest.mark.vcr(filter_headers=["authorization"])
def test_long_term_memory_with_memory_flag(): def test_long_term_memory_with_memory_flag():
from unittest.mock import patch 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( math_researcher = Agent(
role="Researcher", role="Researcher",
@@ -2513,6 +2553,16 @@ def test_long_term_memory_with_memory_flag():
@pytest.mark.vcr(filter_headers=["authorization"]) @pytest.mark.vcr(filter_headers=["authorization"])
def test_using_contextual_memory_with_short_term_memory(): def test_using_contextual_memory_with_short_term_memory():
from unittest.mock import patch 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( math_researcher = Agent(
role="Researcher", role="Researcher",
@@ -2542,6 +2592,16 @@ def test_using_contextual_memory_with_short_term_memory():
@pytest.mark.vcr(filter_headers=["authorization"]) @pytest.mark.vcr(filter_headers=["authorization"])
def test_disabled_memory_using_contextual_memory(): def test_disabled_memory_using_contextual_memory():
from unittest.mock import patch 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( math_researcher = Agent(
role="Researcher", role="Researcher",

View File

@@ -7,10 +7,28 @@ from crewai.memory.long_term.long_term_memory_item import LongTermMemoryItem
@pytest.fixture @pytest.fixture
def long_term_memory(): def long_term_memory():
"""Fixture to create a LongTermMemory instance""" """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() return LongTermMemory()
def test_save_and_search(long_term_memory): 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( memory = LongTermMemoryItem(
agent="test_agent", agent="test_agent",
task="test_task", task="test_task",

View File

@@ -12,6 +12,15 @@ from crewai.task import Task
@pytest.fixture @pytest.fixture
def short_term_memory(): def short_term_memory():
"""Fixture to create a ShortTermMemory instance""" """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( agent = Agent(
role="Researcher", role="Researcher",
goal="Search relevant data and provide results", goal="Search relevant data and provide results",
@@ -29,6 +38,15 @@ def short_term_memory():
def test_save_and_search(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( memory = ShortTermMemoryItem(
data="""test value test value test value test value test value test value 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 test value test value test value test value test value test value