From 568a1b034a151594c61b61279259992bbc94a8dc Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 9 Jul 2026 00:16:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=89=8B=E5=8A=A8=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95=E9=9A=94=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_api_health.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/test_api_health.py b/tests/test_api_health.py index 95cd8c6..4d16293 100644 --- a/tests/test_api_health.py +++ b/tests/test_api_health.py @@ -46,12 +46,30 @@ def test_manual_agent_run_endpoint_starts_background_job(monkeypatch) -> None: monkeypatch.setenv("SIGNALSCOUT_ENV", "test") get_settings.cache_clear() started = [] + engine = create_engine( + "sqlite:///:memory:", + connect_args={"check_same_thread": False}, + poolclass=StaticPool, + future=True, + ) + TestingSessionLocal = sessionmaker(bind=engine, autoflush=False, autocommit=False, future=True) + Base.metadata.create_all(engine) def fake_run_scheduled_job(settings): started.append(settings.env) + def override_get_db(): + # 手动搜索测试只验证接口调度行为,运行中状态查询使用内存库。 + db = TestingSessionLocal() + try: + yield db + finally: + db.close() + monkeypatch.setattr("app.api.routes.run_scheduled_job", fake_run_scheduled_job) - with TestClient(create_app()) as client: + app = create_app() + app.dependency_overrides[get_db] = override_get_db + with TestClient(app) as client: response = client.post("/agent/runs/daily") get_settings.cache_clear()