From bd8918bfabd62b22ec4d3a41d63341fa849d0e58 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 10 Oct 2019 13:24:23 +0100 Subject: [PATCH] use FutureWarning in settings so it's printed (#881) * use FutureWarning in settings so it's printed * fix tests * better warning link * change warning link --- changes/881-samuelcolvin.md | 1 + pydantic/env_settings.py | 5 +++-- tests/test_settings.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 changes/881-samuelcolvin.md diff --git a/changes/881-samuelcolvin.md b/changes/881-samuelcolvin.md new file mode 100644 index 0000000..457f323 --- /dev/null +++ b/changes/881-samuelcolvin.md @@ -0,0 +1 @@ +Use `FutureWarning` instead of `DeprecationWarning` when `alias` instead of `env` is used for settings models diff --git a/pydantic/env_settings.py b/pydantic/env_settings.py index 6fdb8b5..2adc96f 100644 --- a/pydantic/env_settings.py +++ b/pydantic/env_settings.py @@ -73,8 +73,9 @@ class BaseSettings(BaseModel): if field.has_alias: warnings.warn( 'aliases are no longer used by BaseSettings to define which environment variables to read. ' - 'Instead use the "env" field setting. See https://pydantic-docs.helpmanual.io/usage/settings/', - DeprecationWarning, + 'Instead use the "env" field setting. ' + 'See https://pydantic-docs.helpmanual.io/usage/settings/#environment-variable-names', + FutureWarning, ) env_names = [cls.env_prefix + field.name] elif isinstance(env, str): diff --git a/tests/test_settings.py b/tests/test_settings.py index c709099..d0a6ff4 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -208,7 +208,7 @@ def test_env_field(env): def test_aliases_warning(env): - with pytest.warns(DeprecationWarning, match='aliases are no longer used by BaseSettings'): + with pytest.warns(FutureWarning, match='aliases are no longer used by BaseSettings'): class Settings(BaseSettings): foobar: str = 'default value'