Skip to content

测试硬隔离数据库地址,杜绝 pytest 直连真实库#45

Merged
Protocol-zero-0 merged 1 commit into
masterfrom
fix/test-db-isolation
Jun 12, 2026
Merged

测试硬隔离数据库地址,杜绝 pytest 直连真实库#45
Protocol-zero-0 merged 1 commit into
masterfrom
fix/test-db-isolation

Conversation

@Protocol-zero-0

Copy link
Copy Markdown
Contributor

问题

带 .env 的环境(典型:生产机)跑 pytest 时,测试文件的 os.environ.setdefault("DEEPGRAPH_DATABASE_URL", "") 不生效,测试直连真实 Postgres 写入夹具数据。已实际发生一次(21 条测试 agenda 入库,已清理)。

修复

11 个测试文件统一改为无条件 os.environ["DEEPGRAPH_DATABASE_URL"] = "",测试永远落在 tmpdir SQLite。

验证

全套 pytest:15 failed / 505 passed,失败清单与 master 既有一致。

环境里已有 DEEPGRAPH_DATABASE_URL(如生产机加载 .env)时,setdefault
不生效,pytest 会直连真实 Postgres 写入测试数据(已实际发生一次,
污染 21 条 agenda)。改为无条件覆盖,测试永远落在临时 SQLite。
@Protocol-zero-0 Protocol-zero-0 merged commit 1463e5c into master Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant