Skip to content

Commit 5e63dcf

Browse files
committed
ci: fix tests by adding dynamic retry
1 parent 19fe363 commit 5e63dcf

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ dev = [
3434
"langgraph>=1,<2",
3535
"autoevals>=0.0.130,<0.1",
3636
"opentelemetry-instrumentation-threading>=0.59b0,<1",
37+
"tenacity>=9.1.4",
3738
]
3839
docs = [
3940
"pdoc>=15.0.4,<16",

tests/test_core_sdk.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from time import sleep
66

77
import pytest
8+
from tenacity import Retrying, stop_after_delay, wait_fixed
89

910
from langfuse import Langfuse, propagate_attributes
1011
from langfuse._client.resource_manager import LangfuseResourceManager
@@ -337,7 +338,6 @@ def test_create_text_score():
337338

338339
# Ensure data is sent
339340
langfuse.flush()
340-
sleep(2)
341341

342342
# Create a text score
343343
score_id = create_uuid()
@@ -360,23 +360,26 @@ def test_create_text_score():
360360

361361
# Ensure data is sent
362362
langfuse.flush()
363-
sleep(2)
364363

365-
# Retrieve and verify
366-
trace = api_wrapper.get_trace(trace_id)
364+
# Retrieve and verify with retry
365+
for attempt in Retrying(
366+
stop=stop_after_delay(10), wait=wait_fixed(0.1), reraise=True
367+
):
368+
with attempt:
369+
trace = api_wrapper.get_trace(trace_id)
367370

368-
# Find the score we created by name
369-
created_score = next(
370-
(s for s in trace["scores"] if s["name"] == "this-is-a-score"), None
371-
)
372-
assert created_score is not None, "Score not found in trace"
373-
assert created_score["id"] == score_id
374-
assert created_score["dataType"] == "TEXT"
375-
assert created_score["value"] is None
376-
assert (
377-
created_score["stringValue"]
378-
== "This is a detailed text evaluation of the output quality."
379-
)
371+
# Find the score we created by name
372+
created_score = next(
373+
(s for s in trace["scores"] if s["name"] == "this-is-a-score"), None
374+
)
375+
assert created_score is not None, "Score not found in trace"
376+
assert created_score["id"] == score_id
377+
assert created_score["dataType"] == "TEXT"
378+
379+
assert (
380+
created_score["stringValue"]
381+
== "This is a detailed text evaluation of the output quality."
382+
)
380383

381384

382385
def test_create_score_with_custom_timestamp():

uv.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)