From 7b06469a3058f5fe129d48bcf2f3c1c165d7c8e0 Mon Sep 17 00:00:00 2001 From: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Date: Sat, 18 Jun 2022 14:47:42 +0800 Subject: [PATCH] :bug: fix env var not override dotenv file (#1052) --- nonebot/config.py | 5 ++--- tests/.env.test | 1 + tests/test_init.py | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/nonebot/config.py b/nonebot/config.py index af1aa8e4..c998fd7a 100644 --- a/nonebot/config.py +++ b/nonebot/config.py @@ -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()) diff --git a/tests/.env.test b/tests/.env.test index 038f1ffd..ba30adf9 100644 --- a/tests/.env.test +++ b/tests/.env.test @@ -2,3 +2,4 @@ LOG_LEVEL=TRACE NICKNAME=["test"] SUPERUSERS=["test", "fake:faketest"] CONFIG_FROM_ENV= +CONFIG_OVERRIDE=old diff --git a/tests/test_init.py b/tests/test_init.py index a62520d0..f137e9d7 100644 --- a/tests/test_init.py +++ b/tests/test_init.py @@ -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"