Skip to content

Commit 04ee68f

Browse files
authored
chore(llmobs): assert using span events instead of mocks (#11856)
Follow up of #11781 to further clean up LLMObs tests, specifically replacing potentially flaky LLMObs span writer mocks and assertions with the test LLMObsSpanWriter dummy class. Also clean up the `tests/llmobs/conftest.py` file which previously contained a ton of rarely used and sometimes redundant fixtures. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)
1 parent 68fc8f0 commit 04ee68f

6 files changed

+277
-394
lines changed

tests/llmobs/conftest.py

+1-49
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ def pytest_configure(config):
3131
config.addinivalue_line("markers", "vcr_logs: mark test to use recorded request/responses")
3232

3333

34-
@pytest.fixture
35-
def mock_llmobs_span_writer():
36-
patcher = mock.patch("ddtrace.llmobs._llmobs.LLMObsSpanWriter")
37-
LLMObsSpanWriterMock = patcher.start()
38-
m = mock.MagicMock()
39-
LLMObsSpanWriterMock.return_value = m
40-
yield m
41-
patcher.stop()
42-
43-
4434
@pytest.fixture
4535
def mock_llmobs_eval_metric_writer():
4636
patcher = mock.patch("ddtrace.llmobs._llmobs.LLMObsEvalMetricWriter")
@@ -127,44 +117,6 @@ def default_global_config():
127117
return {"_dd_api_key": "<not-a-real-api_key>", "_llmobs_ml_app": "unnamed-ml-app"}
128118

129119

130-
@pytest.fixture
131-
def LLMObs(
132-
mock_llmobs_span_writer, mock_llmobs_eval_metric_writer, mock_llmobs_evaluator_runner, ddtrace_global_config
133-
):
134-
global_config = default_global_config()
135-
global_config.update(ddtrace_global_config)
136-
with override_global_config(global_config):
137-
dummy_tracer = DummyTracer()
138-
llmobs_service.enable(_tracer=dummy_tracer)
139-
yield llmobs_service
140-
llmobs_service.disable()
141-
142-
143-
@pytest.fixture
144-
def AgentlessLLMObs(
145-
mock_llmobs_span_writer,
146-
mock_llmobs_eval_metric_writer,
147-
mock_llmobs_evaluator_runner,
148-
ddtrace_global_config,
149-
):
150-
global_config = default_global_config()
151-
global_config.update(ddtrace_global_config)
152-
global_config.update(dict(_llmobs_agentless_enabled=True))
153-
with override_global_config(global_config):
154-
dummy_tracer = DummyTracer()
155-
llmobs_service.enable(_tracer=dummy_tracer)
156-
yield llmobs_service
157-
llmobs_service.disable()
158-
159-
160-
@pytest.fixture
161-
def disabled_llmobs():
162-
prev = llmobs_service.enabled
163-
llmobs_service.enabled = False
164-
yield
165-
llmobs_service.enabled = prev
166-
167-
168120
@pytest.fixture
169121
def mock_ragas_dependencies_not_present():
170122
import ragas
@@ -177,7 +129,7 @@ def mock_ragas_dependencies_not_present():
177129

178130

179131
@pytest.fixture
180-
def ragas(mock_llmobs_span_writer, mock_llmobs_eval_metric_writer):
132+
def ragas(mock_llmobs_eval_metric_writer):
181133
with override_global_config(dict(_dd_api_key="<not-a-real-key>")):
182134
try:
183135
import ragas

0 commit comments

Comments
 (0)