AutoRpa/rpa_oms/tests/test_local_env.py

22 lines
725 B
Python

# 本机 .env 只补缺,不覆盖已有非空环境变量。
from __future__ import annotations
import os
from rpa_oracle.env import load_env as load_local_env
# 缺的键从文件补上,已有非空环境变量保持不变。
def test_load_local_env_fills_missing_and_keeps_existing(tmp_path, monkeypatch):
monkeypatch.setenv("OMS_REPO", "memory")
monkeypatch.delenv("RPA_ORACLE_PASSWORD", raising=False)
env_file = tmp_path / ".env"
env_file.write_text(
"OMS_REPO=oracle\nRPA_ORACLE_PASSWORD=not-for-git\n# comment\n\n",
encoding="utf-8",
)
load_local_env(env_file)
assert os.environ["OMS_REPO"] == "memory"
assert os.environ["RPA_ORACLE_PASSWORD"] == "not-for-git"