Update LLM event tests to patch the global event bus

This commit is contained in:
lorenzejay
2026-08-05 15:33:49 -07:00
parent 319a20c028
commit bb61cced3c
5 changed files with 10 additions and 10 deletions

View File

@@ -4,7 +4,7 @@ from unittest.mock import MagicMock, patch
import pytest
from crewai.events.event_bus import CrewAIEventsBus
from crewai.events.event_bus import crewai_event_bus
from crewai.events.types.llm_events import (
LLMCallCompletedEvent,
LLMCallStartedEvent,
@@ -31,7 +31,7 @@ class _StubLLM(BaseLLM):
@pytest.fixture
def mock_emit():
with patch.object(CrewAIEventsBus, "emit") as mock:
with patch.object(crewai_event_bus, "emit") as mock:
yield mock

View File

@@ -4,7 +4,7 @@ from unittest.mock import patch
import pytest
from pydantic import BaseModel
from crewai.events.event_bus import CrewAIEventsBus
from crewai.events.event_bus import crewai_event_bus
from crewai.events.types.llm_events import LLMCallCompletedEvent, LLMCallType
from crewai.llm import LLM
from crewai.llms.base_llm import BaseLLM
@@ -203,7 +203,7 @@ class _StubLLM(BaseLLM):
class TestEmitCallCompletedEventPassesUsage:
@pytest.fixture
def mock_emit(self):
with patch.object(CrewAIEventsBus, "emit") as mock:
with patch.object(crewai_event_bus, "emit") as mock:
yield mock
@pytest.fixture

View File

@@ -123,12 +123,12 @@ def test_gemini_completion_initialization_parameters():
def test_gemini_started_event_surfaces_max_output_tokens():
from crewai.events.event_bus import CrewAIEventsBus
from crewai.events.event_bus import crewai_event_bus
from crewai.events.types.llm_events import LLMCallStartedEvent
llm = LLM(model="google/gemini-2.0-flash-001", max_output_tokens=2000, api_key="test-key")
with patch.object(CrewAIEventsBus, "emit") as mock_emit:
with patch.object(crewai_event_bus, "emit") as mock_emit:
llm._emit_call_started_event(messages="hi")
event = mock_emit.call_args[1]["event"]

View File

@@ -534,9 +534,9 @@ def assert_event_count(
@pytest.fixture
def mock_emit() -> MagicMock:
from crewai.events.event_bus import CrewAIEventsBus
from crewai.events.event_bus import crewai_event_bus
with patch.object(CrewAIEventsBus, "emit") as mock_emit:
with patch.object(crewai_event_bus, "emit") as mock_emit:
yield mock_emit

View File

@@ -11,14 +11,14 @@ from unittest.mock import patch
import pytest
from crewai.events.event_bus import CrewAIEventsBus
from crewai.events.event_bus import crewai_event_bus
from crewai.events.types.llm_events import LLMCallCompletedEvent
from crewai.llm import LLM
@pytest.fixture
def mock_emit():
with patch.object(CrewAIEventsBus, "emit") as mock:
with patch.object(crewai_event_bus, "emit") as mock:
yield mock