Skip to content

Commit 1cea6c9

Browse files
committed
fix(test): prevent infinite loop in E2E conftest auto_load_env
`while folder != "/"` 比较 Path 与 str 永远为真,没有 .env 时会死循环卡住整个 E2E 启动。改为按 `folder.parent == folder` 判断到达根目录后退出。 Change-Id: Id62a2804abdffda4f399c5cbbb22a4c6ba41c4e6 Co-developed-by: Claude <noreply@anthropic.com>
1 parent 0624498 commit 1cea6c9

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

tests/e2e/conftest.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@
1515

1616
def auto_load_env():
1717
folder = Path(__file__).parent
18-
while folder != "/":
18+
# 一直向上查找 .env 文件,直到根目录为止
19+
# / Walk up to root looking for a .env file
20+
while True:
1921
dotfile = folder / ".env"
2022
if dotfile.exists():
2123
load_dotenv(dotfile)
2224
print("load .env:", dotfile)
2325
break
26+
if folder.parent == folder:
27+
# 已到根目录,未找到 .env,依赖外部环境变量
28+
# / Reached the filesystem root with no .env found; rely on env vars
29+
break
2430
folder = folder.parent
2531

2632

0 commit comments

Comments
 (0)