test(router): scope FAKE_KEY via pytest monkeypatch fixture
This commit is contained in:
@@ -7,13 +7,17 @@ Run: pytest test_smart_router.py -v
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
|
||||||
from unittest.mock import AsyncMock, MagicMock, patch
|
from unittest.mock import AsyncMock, MagicMock, patch
|
||||||
from smart_router import SmartRouter, Provider
|
from smart_router import SmartRouter, Provider
|
||||||
|
|
||||||
|
|
||||||
# ── Fixtures ──────────────────────────────────────────────────────────────────
|
# ── Fixtures ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def fake_api_key(monkeypatch):
|
||||||
|
monkeypatch.setenv("FAKE_KEY", "test-key")
|
||||||
|
|
||||||
def make_provider(name, healthy=True, configured=True,
|
def make_provider(name, healthy=True, configured=True,
|
||||||
latency=100.0, cost=0.002, errors=0, requests=0):
|
latency=100.0, cost=0.002, errors=0, requests=0):
|
||||||
p = Provider(
|
p = Provider(
|
||||||
@@ -28,9 +32,7 @@ def make_provider(name, healthy=True, configured=True,
|
|||||||
p.avg_latency_ms = latency
|
p.avg_latency_ms = latency
|
||||||
p.error_count = errors
|
p.error_count = errors
|
||||||
p.request_count = requests
|
p.request_count = requests
|
||||||
if configured:
|
if not configured:
|
||||||
os.environ.setdefault("FAKE_KEY", "test-key")
|
|
||||||
else:
|
|
||||||
p.api_key_env = "" # makes is_configured False for non-ollama
|
p.api_key_env = "" # makes is_configured False for non-ollama
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user