ForcePilot/backend/test/unit/channel/conftest.py
Kris bab30f2715
Some checks failed
Deploy VitePress site to Pages / build (push) Has been cancelled
Ruff Format Check / Ruff Format & Lint (push) Has been cancelled
Deploy VitePress site to Pages / Deploy (push) Has been cancelled
feat:0715
2026-07-15 12:30:58 +08:00

29 lines
1.2 KiB
Python

"""Channel unit-test fixtures and environment compatibility patches."""
from __future__ import annotations
# Some local SQLAlchemy installations do not re-export flag_modified from
# sqlalchemy.orm, even though SQLAlchemy 2.0 documents it there. Patch it
# early so channel modules can be imported in test environments.
import sqlalchemy.orm
from sqlalchemy.orm.attributes import flag_modified
if not hasattr(sqlalchemy.orm, "flag_modified"):
sqlalchemy.orm.flag_modified = flag_modified
# `yuxi.channel.message.dispatcher` imports `create_agent_run_view` from
# `yuxi.services.agent_run_service`, which in turn pulls in the heavy and
# partially-broken `yuxi.agents` / `yuxi.knowledge` import chain in some local
# environments. Stub the service module early so channel tests can be collected
# without modifying production source code.
import sys
import types
from unittest.mock import AsyncMock
_agent_run_service_pkg = "yuxi.services.agent_run_service"
if _agent_run_service_pkg not in sys.modules:
_agent_run_service_mod = types.ModuleType(_agent_run_service_pkg)
_agent_run_service_mod.create_agent_run_view = AsyncMock()
sys.modules[_agent_run_service_pkg] = _agent_run_service_mod