Skip to content

Commit e91ee16

Browse files
committed
minor
1 parent 62bd46e commit e91ee16

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

packages/settings-library/tests/test__pydantic_settings.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from pydantic import BaseSettings, validator
1717
from pydantic.fields import ModelField, Undefined
18+
from pytest_simcore.helpers.monkeypatch_envs import setenvs_from_dict
1819

1920

2021
def assert_field_specs(
@@ -50,9 +51,8 @@ class Settings(BaseSettings):
5051
@classmethod
5152
def parse_none(cls, v, values, field: ModelField):
5253
# WARNING: In nullable fields, envs equal to null or none are parsed as None !!
53-
if field.allow_none:
54-
if isinstance(v, str) and v.lower() in ("null", "none"):
55-
return None
54+
if field.allow_none and isinstance(v, str) and v.lower() in ("null", "none"):
55+
return None
5656
return v
5757

5858

@@ -132,15 +132,21 @@ def test_fields_declarations():
132132
def test_construct(monkeypatch):
133133
# from __init__
134134
settings_from_init = Settings(
135-
VALUE=1, VALUE_ALSO_REQUIRED=10, VALUE_NULLABLE_REQUIRED=None
135+
VALUE=1,
136+
VALUE_ALSO_REQUIRED=10,
137+
VALUE_NULLABLE_REQUIRED=None,
136138
)
139+
137140
print(settings_from_init.json(exclude_unset=True, indent=1))
138141

139142
# from env vars
140-
monkeypatch.setenv("VALUE", "1")
141-
monkeypatch.setenv("VALUE_ALSO_REQUIRED", "10")
142-
monkeypatch.setenv(
143-
"VALUE_NULLABLE_REQUIRED", "null"
143+
setenvs_from_dict(
144+
monkeypatch,
145+
{
146+
"VALUE": "1",
147+
"VALUE_ALSO_REQUIRED": "10",
148+
"VALUE_NULLABLE_REQUIRED": "null",
149+
},
144150
) # WARNING: set this env to None would not work w/o ``parse_none`` validator! bug???
145151

146152
settings_from_env = Settings()

0 commit comments

Comments
 (0)