Skip to content

Commit

Permalink
Clean up fixtures and mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun-Kim committed Jan 9, 2025
1 parent d676233 commit 76340ca
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 394 deletions.
50 changes: 1 addition & 49 deletions tests/llmobs/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ def pytest_configure(config):
config.addinivalue_line("markers", "vcr_logs: mark test to use recorded request/responses")


@pytest.fixture
def mock_llmobs_span_writer():
patcher = mock.patch("ddtrace.llmobs._llmobs.LLMObsSpanWriter")
LLMObsSpanWriterMock = patcher.start()
m = mock.MagicMock()
LLMObsSpanWriterMock.return_value = m
yield m
patcher.stop()


@pytest.fixture
def mock_llmobs_eval_metric_writer():
patcher = mock.patch("ddtrace.llmobs._llmobs.LLMObsEvalMetricWriter")
Expand Down Expand Up @@ -127,44 +117,6 @@ def default_global_config():
return {"_dd_api_key": "<not-a-real-api_key>", "_llmobs_ml_app": "unnamed-ml-app"}


@pytest.fixture
def LLMObs(
mock_llmobs_span_writer, mock_llmobs_eval_metric_writer, mock_llmobs_evaluator_runner, ddtrace_global_config
):
global_config = default_global_config()
global_config.update(ddtrace_global_config)
with override_global_config(global_config):
dummy_tracer = DummyTracer()
llmobs_service.enable(_tracer=dummy_tracer)
yield llmobs_service
llmobs_service.disable()


@pytest.fixture
def AgentlessLLMObs(
mock_llmobs_span_writer,
mock_llmobs_eval_metric_writer,
mock_llmobs_evaluator_runner,
ddtrace_global_config,
):
global_config = default_global_config()
global_config.update(ddtrace_global_config)
global_config.update(dict(_llmobs_agentless_enabled=True))
with override_global_config(global_config):
dummy_tracer = DummyTracer()
llmobs_service.enable(_tracer=dummy_tracer)
yield llmobs_service
llmobs_service.disable()


@pytest.fixture
def disabled_llmobs():
prev = llmobs_service.enabled
llmobs_service.enabled = False
yield
llmobs_service.enabled = prev


@pytest.fixture
def mock_ragas_dependencies_not_present():
import ragas
Expand All @@ -177,7 +129,7 @@ def mock_ragas_dependencies_not_present():


@pytest.fixture
def ragas(mock_llmobs_span_writer, mock_llmobs_eval_metric_writer):
def ragas(mock_llmobs_eval_metric_writer):
with override_global_config(dict(_dd_api_key="<not-a-real-key>")):
try:
import ragas
Expand Down
Loading

0 comments on commit 76340ca

Please sign in to comment.