From 57df7f52023923c96965ce231ca1d74f954e898c Mon Sep 17 00:00:00 2001 From: Vidit Ostwal <110953813+Vidit-Ostwal@users.noreply.github.com> Date: Wed, 9 Sep 2026 23:46:37 +0530 Subject: [PATCH] test(bedrock): restore provider module after import test (#7355) Co-authored-by: Lorenze Jay <63378463+lorenzejay@users.noreply.github.com> --- lib/crewai/tests/llms/bedrock/test_bedrock.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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")