From 840073557372f2bf541e549dba4b5e37440d9215 Mon Sep 17 00:00:00 2001 From: Priyanka Punukollu Date: Thu, 26 Feb 2026 21:31:47 -0600 Subject: [PATCH] =?UTF-8?q?fix:=20restore=20126=20tests=20=E2=80=94=20add?= =?UTF-8?q?=20conftest=20mock=20for=20teleport=20API,=20fix=20async=20conf?= =?UTF-8?q?ig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- agent/evals/conftest.py | 53 +++++++++++++++++++++++++++++++++++++++++ agent/pytest.ini | 3 +++ 2 files changed, 56 insertions(+) create mode 100644 agent/evals/conftest.py create mode 100644 agent/pytest.ini diff --git a/agent/evals/conftest.py b/agent/evals/conftest.py new file mode 100644 index 000000000..b1d0c5d91 --- /dev/null +++ b/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 diff --git a/agent/pytest.ini b/agent/pytest.ini new file mode 100644 index 000000000..54e4f8834 --- /dev/null +++ b/agent/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +asyncio_mode = strict +testpaths = evals