Browse Source

fix: restore 126 tests — add conftest mock for teleport API, fix async config

- Created agent/evals/conftest.py: autouse fixture patches teleport_api._fetch_from_teleport
  and search_city_slug to bypass all live HTTP calls during tests
- Tests now use HARDCODED_FALLBACK data for all cities (deterministic, instant)
- Created agent/pytest.ini with asyncio_mode=strict and testpaths=evals
- All 126 tests collected and passing: 0 failures, 0 skips

Made-with: Cursor
pull/6453/head
Priyanka Punukollu 1 month ago
parent
commit
8400735573
  1. 53
      agent/evals/conftest.py
  2. 3
      agent/pytest.ini

53
agent/evals/conftest.py

@ -0,0 +1,53 @@
"""
pytest conftest for the AgentForge eval suite.
Two responsibilities:
1. Patches teleport_api._fetch_from_teleport to return None immediately,
bypassing all live HTTP calls. This forces get_city_housing_data to fall
back to HARDCODED_FALLBACK data instantly. Tests run in <1s total.
2. Ensures pytest-asyncio is configured for STRICT mode (set in pytest.ini).
All async tests carry @pytest.mark.asyncio (they already do).
"""
import os
import sys
# Make 'agent/' and 'agent/tools/' importable from any working directory
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "tools"))
import pytest
# ---------------------------------------------------------------------------
# Teleport API mock — eliminates all live network calls during tests
# ---------------------------------------------------------------------------
@pytest.fixture(autouse=True)
def mock_teleport_no_network(monkeypatch):
"""
Patches teleport_api._fetch_from_teleport to return None immediately.
This forces get_city_housing_data to use HARDCODED_FALLBACK for every
city, with zero HTTP requests and zero wait time.
Also patches search_city_slug to return from the in-memory cache only,
so no DNS/HTTP calls are made during slug resolution.
autouse=True applies this to every test automatically.
"""
try:
import teleport_api
async def _instant_fetch(city_name: str, slug: str):
"""Skip live API call — triggers fallback path immediately."""
return None
async def _cache_only_slug(city_name: str):
"""Return from cache or None — no HTTP search calls."""
lower = city_name.lower().strip()
return teleport_api._slug_cache.get(lower)
monkeypatch.setattr(teleport_api, "_fetch_from_teleport", _instant_fetch)
monkeypatch.setattr(teleport_api, "search_city_slug", _cache_only_slug)
except ImportError:
pass # teleport_api not importable in this test context — skip

3
agent/pytest.ini

@ -0,0 +1,3 @@
[pytest]
asyncio_mode = strict
testpaths = evals
Loading…
Cancel
Save