Files
crewAI/lib/crewai/tests/llms
Joao Moura ad0523b92c [EPD-196] Fix pre-existing test-isolation leak breaking azure responses mocks
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>
2026-07-13 23:25:23 -07:00
..
2026-06-14 04:19:48 -03:00
2025-10-20 14:10:19 -07:00