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.
This commit is contained in:
lorenzejay
2026-07-08 17:25:45 -07:00
parent 8307d4ba14
commit e72b2039f9

View File

@@ -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")