diff --git a/tests/test_litellm/llms/stepfun/test_stepfun_pricing.py b/tests/test_litellm/llms/stepfun/test_stepfun_pricing.py index 936e2d38d22..da0e36a168e 100644 --- a/tests/test_litellm/llms/stepfun/test_stepfun_pricing.py +++ b/tests/test_litellm/llms/stepfun/test_stepfun_pricing.py @@ -1,19 +1,21 @@ import math +import pytest + import litellm from litellm.cost_calculator import cost_per_token -def _load_local_model_cost(): - import os - - os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True" - litellm.model_cost = litellm.get_model_cost_map(url="") +@pytest.fixture +def local_model_cost_map(monkeypatch): + monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True") + monkeypatch.setattr(litellm, "model_cost", litellm.get_model_cost_map(url="")) + litellm.get_model_info.cache_clear() + yield + litellm.get_model_info.cache_clear() -def test_stepfun_models_in_model_cost(): - _load_local_model_cost() - +def test_stepfun_models_in_model_cost(local_model_cost_map): stepfun_models = [ "stepfun/step-3.7-flash", "stepfun/step-3.5-flash", @@ -25,9 +27,7 @@ def test_stepfun_models_in_model_cost(): assert litellm.model_cost[model]["litellm_provider"] == "stepfun" -def test_stepfun_step_35_flash_cost_calculation(): - _load_local_model_cost() - +def test_stepfun_step_35_flash_cost_calculation(local_model_cost_map): prompt_cost, completion_cost = cost_per_token( model="stepfun/step-3.5-flash", prompt_tokens=1000000, @@ -39,9 +39,7 @@ def test_stepfun_step_35_flash_cost_calculation(): assert math.isclose(completion_cost, 0.30, rel_tol=1e-6) -def test_stepfun_step_37_flash_cost_calculation(): - _load_local_model_cost() - +def test_stepfun_step_37_flash_cost_calculation(local_model_cost_map): prompt_cost, completion_cost = cost_per_token( model="stepfun/step-3.7-flash", prompt_tokens=1000000, @@ -53,9 +51,7 @@ def test_stepfun_step_37_flash_cost_calculation(): assert math.isclose(completion_cost, 1.15, rel_tol=1e-6) -def test_stepfun_step_35_flash_cache_hit_cost(): - _load_local_model_cost() - +def test_stepfun_step_35_flash_cache_hit_cost(local_model_cost_map): prompt_cost, _ = cost_per_token( model="stepfun/step-3.5-flash", prompt_tokens=0, @@ -67,8 +63,6 @@ def test_stepfun_step_35_flash_cache_hit_cost(): assert math.isclose(prompt_cost, 0.02, rel_tol=1e-6) -def test_stepfun_reasoning_models_support_reasoning(): - _load_local_model_cost() - +def test_stepfun_reasoning_models_support_reasoning(local_model_cost_map): for model in ("stepfun/step-3.5-flash", "stepfun/step-3.5-flash-2603", "stepfun/step-3.7-flash"): assert litellm.model_cost[model]["supports_reasoning"] is True