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