Skip to content

Commit 233aae3

Browse files
committed
ref: consolidate test_handle_empty_results
1 parent dd16824 commit 233aae3

1 file changed

Lines changed: 4 additions & 27 deletions

File tree

py/src/braintrust/test_trace.py

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -232,35 +232,9 @@ async def fetch_fn(span_type):
232232
no_type_result = await fetcher.get_spans(span_type=[""])
233233
assert len(no_type_result) == 2
234234

235-
@pytest.mark.asyncio
236-
async def test_handle_empty_results(self):
237-
"""Test that empty results don't permanently cache, allowing re-fetch when data becomes available."""
238-
call_count = 0
239-
mock_spans = [make_span("span-1", "llm")]
240-
241-
async def fetch_fn(span_type):
242-
nonlocal call_count
243-
call_count += 1
244-
if call_count == 1:
245-
return []
246-
return mock_spans
247-
248-
fetcher = CachedSpanFetcher(fetch_fn=fetch_fn)
249-
250-
# First call returns empty
251-
result = await fetcher.get_spans()
252-
assert len(result) == 0
253-
assert call_count == 1
254-
255-
# Second call should re-fetch since first was empty
256-
result = await fetcher.get_spans()
257-
assert call_count == 2
258-
assert len(result) == 1
259-
assert result[0].span_id == "span-1"
260-
261235
@pytest.mark.asyncio
262236
async def test_empty_then_populated_refetches(self):
263-
"""Test that fetch_fn returning [] first, then spans on second call, works correctly."""
237+
"""Test that empty results don't permanently cache, allowing re-fetch when data becomes available."""
264238
call_count = 0
265239
spans = [make_span("span-1", "llm"), make_span("span-2", "function")]
266240

@@ -273,9 +247,12 @@ async def fetch_fn(span_type):
273247

274248
fetcher = CachedSpanFetcher(fetch_fn=fetch_fn)
275249

250+
# First call returns empty
276251
result1 = await fetcher.get_spans()
277252
assert len(result1) == 0
253+
assert call_count == 1
278254

255+
# Second call should re-fetch since first was empty
279256
result2 = await fetcher.get_spans()
280257
assert call_count == 2
281258
assert len(result2) == 2

0 commit comments

Comments
 (0)