From 0e1cc4ca55f71d81a1d0c84140ca70b8306703ef Mon Sep 17 00:00:00 2001 From: CompleteDotTech <5861166+CompleteDotTech@users.noreply.github.com> Date: Tue, 1 Dec 2026 07:56:03 -0500 Subject: [PATCH] test: stabilize offline teacher cost accounting Signed-off-by: CompleteDotTech <5861166+CompleteDotTech@users.noreply.github.com> --- tests/test_dspy_compat.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_dspy_compat.py b/tests/test_dspy_compat.py index 388d539..aa2960a 100644 --- a/tests/test_dspy_compat.py +++ b/tests/test_dspy_compat.py @@ -79,7 +79,12 @@ def log_message(self, *args): @pytest.mark.optional def test_teacher_uses_pinned_engine_overrides_and_unchanged_metering_against_loopback_double(monkeypatch): pytest.importorskip("dspy") - pytest.importorskip("litellm") + litellm = pytest.importorskip("litellm") + # Use synthetic rates so metering stays independent of the published model catalog. + monkeypatch.setitem(litellm.model_cost, "deepseek/deepseek-flash", { + "input_cost_per_token": 0.000001, "output_cost_per_token": 0.000002, + "litellm_provider": "deepseek", "mode": "chat", + }) _Provider.seen = [] server = HTTPServer(("127.0.0.1", 0), _Provider) thread = threading.Thread(target=server.serve_forever, daemon=True) @@ -105,7 +110,8 @@ def test_teacher_uses_pinned_engine_overrides_and_unchanged_metering_against_loo assert account["reported_input_tokens"] == 10 and account["reported_output_tokens"] == 5 assert account["observed_response_models"] == ["deepseek-flash"] # Cost metadata comes from LiteLLM's response; DSPy 3.4 native engines would report it unknown. - assert account["cost_unknown_calls"] == 0 and account["sdk_estimated_cost"] is not None + assert account["cost_unknown_calls"] == 0 + assert account["sdk_estimated_cost"] == pytest.approx(0.000020) assert account["dollar_cost"] is None assert teacher.lm.history == [] and teacher.revise.history == [] assert teacher.lm.cache is False