mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-07-25 08:45:09 +00:00
Not caused by this PR's change — a latent leak in test_openai_completion_module_is_imported exposed by pytest-randomly's per-run ordering (CI seed 756721157 placed it before the azure responses tests on the same xdist worker of the py3.10 shard). Mechanism: the test monkeypatch.delitem's crewai.llms.providers.openai.completion from sys.modules and re-imports it, which rebinds the parent package's `completion` attribute to the new module object. monkeypatch teardown restores only the sys.modules entry, leaving the package attribute pointing at the stale re-imported module. On Python 3.10, `from crewai.llms.providers.openai.completion import OpenAICompletion` resolves through the parent package attribute while mock.patch targets the sys.modules entry, so the azure responses tests' OpenAICompletion patch silently missed and a real delegate was built (last_response_id None, reset_chain never called). Python 3.11+ resolves via sys.modules, hiding the leak. Fix: record the package attribute with monkeypatch.setattr alongside the delitem so teardown restores both bindings consistently. Reproduced on pristine origin/main (py3.10, -n0, culprit test followed by the three azure responses tests) and verified green after the fix, including a replay of the failing CI worker's exact 181-test order. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>