test(budget): isolate user_cost.json writes and pin positive projected cost

This commit is contained in:
soroush5 2026-09-04 18:53:01 +03:30
parent 47bffe38a1
commit 81f19176fc

View file

@ -4,7 +4,10 @@ from litellm.budget_manager import BudgetManager
@pytest.fixture()
def manager() -> BudgetManager:
def manager(tmp_path, monkeypatch) -> BudgetManager:
# BudgetManager persists to ./user_cost.json via a background thread;
# isolate cwd so the suite never litters the repo or races parallel workers.
monkeypatch.chdir(tmp_path)
bm = BudgetManager(project_name="test", client_type="local")
bm.create_budget(total_budget=10, user="u", duration="daily")
return bm
@ -16,7 +19,7 @@ def test_projected_cost_string_content(manager: BudgetManager):
messages=[{"role": "user", "content": "hello"}],
user="u",
)
assert cost >= 0
assert cost > 0
def test_projected_cost_vision_content(manager: BudgetManager):
@ -33,7 +36,7 @@ def test_projected_cost_vision_content(manager: BudgetManager):
],
user="u",
)
assert cost >= 0
assert cost > 0
def test_projected_cost_none_and_missing_content(manager: BudgetManager):