Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
test(bedrock): isolate session credential test (#7388)
Vidit Ostwal004f7b58d56b
diff --git a/lib/crewai/tests/llms/bedrock/test_bedrock.py b/lib/crewai/tests/llms/bedrock/test_bedrock.pyindex 87c0d6c09..fd79198fc 100644--- a/lib/crewai/tests/llms/bedrock/test_bedrock.py+++ b/lib/crewai/tests/llms/bedrock/test_bedrock.py@@ -1,6 +1,4 @@import os-import sys-import typesfrom unittest.mock import patch, MagicMockimport pytest@@ -8,6 +6,7 @@ from crewai.llm import LLMfrom crewai.crew import Crewfrom crewai.agent import Agentfrom crewai.task import Task+from crewai.llms.providers.bedrock import completion as bedrock_completiondef _create_bedrock_mocks():@@ -134,25 +133,6 @@ def test_bedrock_completion_is_used_when_bedrock_provider():assert llm.model == "anthropic.claude-3-5-sonnet-20241022-v2:0"-def test_bedrock_completion_module_is_imported(monkeypatch):- """- Test that the completion module is properly imported when using Bedrock provider- """- module_name = "crewai.llms.providers.bedrock.completion"-- # Restore the original module after this test so collected class references- # still match the provider returned by LLM in subsequent tests.- monkeypatch.delitem(sys.modules, module_name, raising=False)-- LLM(model="bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0")-- assert module_name in sys.modules- completion_mod = sys.modules[module_name]- assert isinstance(completion_mod, types.ModuleType)-- assert hasattr(completion_mod, 'BedrockCompletion')--def test_native_bedrock_raises_error_when_initialization_fails():"""Test that LLM raises ImportError when native Bedrock completion fails.@@ -602,8 +582,10 @@ def test_bedrock_tool_conversion():assert "inputSchema" in bedrock_tools[0]["toolSpec"]-def test_bedrock_environment_variable_credentials():+def test_bedrock_environment_variable_credentials(monkeypatch):"""Pass AWS credentials and region from the environment to boto3."""+ monkeypatch.delenv("AWS_SESSION_TOKEN", raising=False)+with (patch.dict(os.environ,@@ -614,13 +596,12 @@ def test_bedrock_environment_variable_credentials():},clear=False,),- patch(- "crewai.llms.providers.bedrock.completion.Session"- ) as mock_session_class,+ patch.object(bedrock_completion, "Session") as mock_session_class,):mock_session_class.return_value.client.return_value = MagicMock()- LLM(model="bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0")+ llm = LLM(model="bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0")+ assert type(llm) is bedrock_completion.BedrockCompletionmock_session_class.assert_called_once_with(aws_access_key_id="test-access-key-123",aws_secret_access_key="test-secret-key-456",