mirror of
https://github.com/nonebot/nonebot2.git
synced 2024-11-24 00:55:07 +08:00
🐛 fix env var not override dotenv file (#1052)
This commit is contained in:
parent
a62a49d477
commit
7b06469a30
@ -83,9 +83,8 @@ class CustomEnvSettings(EnvSettingsSource):
|
||||
d[field.alias] = env_val
|
||||
|
||||
if env_file_vars:
|
||||
for env_name, env_val in env_file_vars.items():
|
||||
if (env_val is None or len(env_val) == 0) and env_name in env_vars:
|
||||
env_val = env_vars[env_name]
|
||||
for env_name in env_file_vars.keys():
|
||||
env_val = env_vars[env_name]
|
||||
try:
|
||||
if env_val:
|
||||
env_val = settings.__config__.json_loads(env_val.strip())
|
||||
|
@ -2,3 +2,4 @@ LOG_LEVEL=TRACE
|
||||
NICKNAME=["test"]
|
||||
SUPERUSERS=["test", "fake:faketest"]
|
||||
CONFIG_FROM_ENV=
|
||||
CONFIG_OVERRIDE=old
|
||||
|
@ -3,6 +3,7 @@ import os
|
||||
import pytest
|
||||
|
||||
os.environ["CONFIG_FROM_ENV"] = '{"test": "test"}'
|
||||
os.environ["CONFIG_OVERRIDE"] = "new"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@ -25,6 +26,7 @@ async def test_init(nonebug_init):
|
||||
|
||||
config = get_driver().config
|
||||
assert config.config_from_env == {"test": "test"}
|
||||
assert config.config_override == "new"
|
||||
assert config.config_from_init == "init"
|
||||
assert config.common_config == "common"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user