mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
fix(e2e): guard spend-log truncate on skip and stop returning unrelated priced rows
This commit is contained in:
parent
59855b5417
commit
0c57b54d77
2 changed files with 19 additions and 5 deletions
|
|
@ -22,6 +22,9 @@ from e2e_config import PROXY_BASE_URL
|
|||
from lifecycle import GatewayProvider, ResourceManager
|
||||
|
||||
|
||||
_E2E_TEST_RAN = pytest.StashKey[bool]()
|
||||
|
||||
|
||||
def pytest_configure(config: pytest.Config) -> None:
|
||||
config.addinivalue_line(
|
||||
"markers",
|
||||
|
|
@ -29,12 +32,23 @@ def pytest_configure(config: pytest.Config) -> None:
|
|||
)
|
||||
|
||||
|
||||
def pytest_runtest_call(item: pytest.Item) -> None:
|
||||
"""Mark that an e2e test body actually ran (not skipped at setup). Skipped
|
||||
sessions never reach this hook, so the session-finish cleanup can use it as a
|
||||
guard before truncating the spend-log DB."""
|
||||
item.session.stash[_E2E_TEST_RAN] = True
|
||||
|
||||
|
||||
def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None:
|
||||
"""Once the whole e2e session is done (all suites), truncate the spend logs so
|
||||
the DB doesn't accumulate test rows. Best-effort: a cleanup failure (no DB
|
||||
reachable) must not fail the run. The spend_tracking dir goes on sys.path only
|
||||
for this import and is removed after, so a broader `pytest tests/` run is not
|
||||
left with a mutated path."""
|
||||
the DB doesn't accumulate test rows. Skipped sessions (no live proxy, no test
|
||||
actually executed) leave the DB alone so a `DATABASE_URL` pointing at a shared
|
||||
instance is never wiped without an e2e run. Best-effort: a cleanup failure (no
|
||||
DB reachable) must not fail the run. The spend_tracking dir goes on sys.path
|
||||
only for this import and is removed after, so a broader `pytest tests/` run is
|
||||
not left with a mutated path."""
|
||||
if not session.stash.get(_E2E_TEST_RAN, False):
|
||||
return
|
||||
spend_dir = str(Path(__file__).parent / "spend_tracking")
|
||||
sys.path.insert(0, spend_dir)
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@ def _poll_breakdown_row(
|
|||
for row in priced:
|
||||
if response_id and row.request_id == response_id:
|
||||
return row
|
||||
if priced:
|
||||
if priced and response_id is None:
|
||||
return priced[0]
|
||||
time.sleep(client.gateway.poll_interval)
|
||||
pytest.fail("no spend row with a cost breakdown landed before the deadline")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue