From 041dc01789452e5adadf9956bec9a1d446da4350 Mon Sep 17 00:00:00 2001 From: Protocol Zero <257158451+Protocol-zero-0@users.noreply.github.com> Date: Fri, 12 Jun 2026 20:45:27 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=A1=AC=E9=9A=94=E7=A6=BB?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E5=9C=B0=E5=9D=80:setdefault=20?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=BC=BA=E5=88=B6=E7=BD=AE=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 环境里已有 DEEPGRAPH_DATABASE_URL(如生产机加载 .env)时,setdefault 不生效,pytest 会直连真实 Postgres 写入测试数据(已实际发生一次, 污染 21 条 agenda)。改为无条件覆盖,测试永远落在临时 SQLite。 --- tests/test_agenda_budget.py | 2 +- tests/test_agenda_contract.py | 2 +- tests/test_agenda_orchestrator.py | 2 +- tests/test_agenda_review_loop.py | 2 +- tests/test_agenda_routes.py | 2 +- tests/test_agenda_scope.py | 2 +- tests/test_agenda_selector.py | 2 +- tests/test_direction_intake.py | 2 +- tests/test_evidence_gate.py | 2 +- tests/test_evidence_gate_routes.py | 2 +- tests/test_manuscript_routes.py | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/test_agenda_budget.py b/tests/test_agenda_budget.py index 2346ef8..a28b8dd 100644 --- a/tests/test_agenda_budget.py +++ b/tests/test_agenda_budget.py @@ -12,7 +12,7 @@ import unittest from pathlib import Path -os.environ.setdefault("DEEPGRAPH_DATABASE_URL", "") +os.environ["DEEPGRAPH_DATABASE_URL"] = "" # force SQLite tmpdir; never touch a real DB from the environment SAMPLE_AGENDA = { diff --git a/tests/test_agenda_contract.py b/tests/test_agenda_contract.py index 6f64289..c4c0d16 100644 --- a/tests/test_agenda_contract.py +++ b/tests/test_agenda_contract.py @@ -16,7 +16,7 @@ from pathlib import Path # Force SQLite for tests -os.environ.setdefault("DEEPGRAPH_DATABASE_URL", "") +os.environ["DEEPGRAPH_DATABASE_URL"] = "" # force SQLite tmpdir; never touch a real DB from the environment from contracts.agenda import ( # noqa: E402 AgendaReview, diff --git a/tests/test_agenda_orchestrator.py b/tests/test_agenda_orchestrator.py index 21c8cc4..b9ff736 100644 --- a/tests/test_agenda_orchestrator.py +++ b/tests/test_agenda_orchestrator.py @@ -7,7 +7,7 @@ import unittest from pathlib import Path -os.environ.setdefault("DEEPGRAPH_DATABASE_URL", "") +os.environ["DEEPGRAPH_DATABASE_URL"] = "" # force SQLite tmpdir; never touch a real DB from the environment SAMPLE_AGENDA_DICT = { diff --git a/tests/test_agenda_review_loop.py b/tests/test_agenda_review_loop.py index f295827..e8eaaf0 100644 --- a/tests/test_agenda_review_loop.py +++ b/tests/test_agenda_review_loop.py @@ -11,7 +11,7 @@ import httpx -os.environ.setdefault("DEEPGRAPH_DATABASE_URL", "") +os.environ["DEEPGRAPH_DATABASE_URL"] = "" # force SQLite tmpdir; never touch a real DB from the environment SAMPLE_AGENDA_DICT = { diff --git a/tests/test_agenda_routes.py b/tests/test_agenda_routes.py index c2116e5..a3cbde2 100644 --- a/tests/test_agenda_routes.py +++ b/tests/test_agenda_routes.py @@ -14,7 +14,7 @@ import unittest from pathlib import Path -os.environ.setdefault("DEEPGRAPH_DATABASE_URL", "") +os.environ["DEEPGRAPH_DATABASE_URL"] = "" # force SQLite tmpdir; never touch a real DB from the environment SAMPLE_AGENDA_DICT = { diff --git a/tests/test_agenda_scope.py b/tests/test_agenda_scope.py index d663ad6..a6b5805 100644 --- a/tests/test_agenda_scope.py +++ b/tests/test_agenda_scope.py @@ -12,7 +12,7 @@ import unittest from pathlib import Path -os.environ.setdefault("DEEPGRAPH_DATABASE_URL", "") +os.environ["DEEPGRAPH_DATABASE_URL"] = "" # force SQLite tmpdir; never touch a real DB from the environment MEDICAL_AGENDA = { diff --git a/tests/test_agenda_selector.py b/tests/test_agenda_selector.py index 4c59282..5d241e1 100644 --- a/tests/test_agenda_selector.py +++ b/tests/test_agenda_selector.py @@ -7,7 +7,7 @@ import unittest from pathlib import Path -os.environ.setdefault("DEEPGRAPH_DATABASE_URL", "") +os.environ["DEEPGRAPH_DATABASE_URL"] = "" # force SQLite tmpdir; never touch a real DB from the environment SAMPLE_AGENDA_DICT = { diff --git a/tests/test_direction_intake.py b/tests/test_direction_intake.py index 82d3398..82f0a9c 100644 --- a/tests/test_direction_intake.py +++ b/tests/test_direction_intake.py @@ -14,7 +14,7 @@ import unittest from pathlib import Path -os.environ.setdefault("DEEPGRAPH_DATABASE_URL", "") +os.environ["DEEPGRAPH_DATABASE_URL"] = "" # force SQLite tmpdir; never touch a real DB from the environment sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts")) diff --git a/tests/test_evidence_gate.py b/tests/test_evidence_gate.py index e7e6915..5ed5517 100644 --- a/tests/test_evidence_gate.py +++ b/tests/test_evidence_gate.py @@ -13,7 +13,7 @@ import unittest from pathlib import Path -os.environ.setdefault("DEEPGRAPH_DATABASE_URL", "") +os.environ["DEEPGRAPH_DATABASE_URL"] = "" # force SQLite tmpdir; never touch a real DB from the environment SAMPLE_AGENDA_DICT = { diff --git a/tests/test_evidence_gate_routes.py b/tests/test_evidence_gate_routes.py index f0bd55a..c4eea41 100644 --- a/tests/test_evidence_gate_routes.py +++ b/tests/test_evidence_gate_routes.py @@ -13,7 +13,7 @@ import unittest from pathlib import Path -os.environ.setdefault("DEEPGRAPH_DATABASE_URL", "") +os.environ["DEEPGRAPH_DATABASE_URL"] = "" # force SQLite tmpdir; never touch a real DB from the environment SAMPLE_AGENDA_DICT = { diff --git a/tests/test_manuscript_routes.py b/tests/test_manuscript_routes.py index 0bd3913..32e854a 100644 --- a/tests/test_manuscript_routes.py +++ b/tests/test_manuscript_routes.py @@ -18,7 +18,7 @@ import unittest from pathlib import Path -os.environ.setdefault("DEEPGRAPH_DATABASE_URL", "") +os.environ["DEEPGRAPH_DATABASE_URL"] = "" # force SQLite tmpdir; never touch a real DB from the environment class ManuscriptRoutesSmokeTests(unittest.TestCase):