测试硬隔离数据库地址,杜绝 pytest 直连真实库#45
Merged
Merged
Conversation
环境里已有 DEEPGRAPH_DATABASE_URL(如生产机加载 .env)时,setdefault 不生效,pytest 会直连真实 Postgres 写入测试数据(已实际发生一次, 污染 21 条 agenda)。改为无条件覆盖,测试永远落在临时 SQLite。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
带 .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 既有一致。