| 123456789101112131415161718192021222324252627282930 |
- # -*- coding: utf-8 -*-
- """
- 测试文件
- 注意:使用普通的 def 定义测试函数,不要使用 async def
- 执行命令: pytest tests/test.py
- """
- import pytest
- import websockets
- from fastapi.testclient import TestClient
- def test_check_health(test_client: TestClient):
- # 替换成你的实际 WS 地址(和前端一致)
- ws_url = "ws://127.0.0.1:8001/api/v1/ai/mcp/ws/chat"
- try:
- async with websockets.connect(ws_url) as websocket:
- print("✅ WS 连接成功!")
- # 接收后端推送的消息
- while True:
- msg = await websocket.recv()
- print("收到消息:", msg)
- except Exception as e:
- print("❌ WS 连接失败:", str(e))
- # 运行所有测试
- if __name__ == "__main__":
- pytest.main(["-v", "tests/test_main.py"])
|