Skip to content

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.

test(bedrock): restore provider module after import test (#7355)

Vidit Ostwal57df7f520239
diff --git a/lib/crewai/tests/llms/bedrock/test_bedrock.py b/lib/crewai/tests/llms/bedrock/test_bedrock.py
index d48334d31..0127ffd62 100644
--- a/lib/crewai/tests/llms/bedrock/test_bedrock.py
+++ b/lib/crewai/tests/llms/bedrock/test_bedrock.py
@@ -134,14 +134,15 @@ 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():
+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"
- if module_name in sys.modules:
- del sys.modules[module_name]
+ # 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")