From e72b2039f9778b122168e4c9ddc263c37ae12687 Mon Sep 17 00:00:00 2001 From: lorenzejay Date: Wed, 8 Jul 2026 17:25:45 -0700 Subject: [PATCH] Refactor OpenAI completion module test to restore original module state - Added logic to save and restore the original OpenAI completion module during the test to prevent issues with class re-imports affecting subsequent tests. - Ensured that the test checks for the presence of the module and its attributes only after the module is properly reloaded. - Improved test reliability by avoiding potential failures due to module state changes across tests. --- lib/crewai/tests/llms/openai/test_openai.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/crewai/tests/llms/openai/test_openai.py b/lib/crewai/tests/llms/openai/test_openai.py index fd1b48e39..9170487c5 100644 --- a/lib/crewai/tests/llms/openai/test_openai.py +++ b/lib/crewai/tests/llms/openai/test_openai.py @@ -134,14 +134,13 @@ def test_openai_is_default_provider_without_explicit_llm_set_on_agent(): -def test_openai_completion_module_is_imported(): +def test_openai_completion_module_is_imported(monkeypatch): """ Test that the completion module is properly imported when using OpenAI provider """ module_name = "crewai.llms.providers.openai.completion" - if module_name in sys.modules: - del sys.modules[module_name] + monkeypatch.delitem(sys.modules, module_name, raising=False) LLM(model="gpt-4o")