Enable pytest-asyncio tests in CI (#3)

* Set asyncio_mode="auto" in pytest.ini config

Xref https://pytest-asyncio.readthedocs.io/en/latest/reference/configuration.html#asyncio-mode

* Add test-python GitHub Actions CI workflow

* Add `--color=yes` flag to force GitHub Actions logs to have color

Xref https://github.com/pytest-dev/pytest/issues/7443

* Refactor contents of test_api.py slightly

Using some ruff rules

* Delete test_api.py

* Make test_get_place async

* Make get_place async, and call .ainvoke method on it
This commit is contained in:
Wei Ji
2025-12-04 13:09:02 +00:00
committed by GitHub
parent 93b405cda4
commit 2d5af2adb9
5 changed files with 54 additions and 53 deletions
-45
View File
@@ -1,45 +0,0 @@
import pytest
import pytest_asyncio
from httpx import AsyncClient, ASGITransport
from uuid import uuid4
from geo_assistant.api.app import app
from geo_assistant.agent.graph import create_graph
@pytest_asyncio.fixture
async def initialized_app():
"""Initialize the app's chatbot before testing"""
# Manually initialize the chatbot as the lifespan would
app.state.chatbot = await create_graph()
yield app
# Cleanup if needed
if hasattr(app.state, "chatbot"):
del app.state.chatbot
@pytest.mark.asyncio
async def test_hello_world(initialized_app):
"""Hello world test for the API"""
async with AsyncClient(
transport=ASGITransport(app=initialized_app), base_url="http://test"
) as client:
thread_id = uuid4()
response = await client.post(
"/chat",
json={
"agent_state_input": {
"messages": [{"content": "Hello, world!", "type": "human"}],
"feature_collection": None,
},
"thread_id": str(thread_id),
},
)
assert response.status_code == 200
assert response.headers["content-type"] == "application/x-ndjson; charset=utf-8"
# Read the streaming response
content = response.text
assert content is not None
assert len(content) > 0