mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
28 lines
784 B
Python
28 lines
784 B
Python
import pytest
|
|
|
|
from pydantic import BaseSettings, ValidationError
|
|
|
|
|
|
class SimpleSettings(BaseSettings):
|
|
apple: str = ...
|
|
|
|
|
|
def test_sub_env(env):
|
|
env.set('APP_APPLE', 'hello')
|
|
s = SimpleSettings()
|
|
assert s.apple == 'hello'
|
|
|
|
|
|
def test_sub_env_override(env):
|
|
env.set('APP_APPLE', 'hello')
|
|
s = SimpleSettings(apple='goodbye')
|
|
assert s.apple == 'goodbye'
|
|
|
|
|
|
def test_sub_env_missing():
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
SimpleSettings()
|
|
assert exc_info.value.args[0] == ('1 error validating input: {"apple": {"error_msg": "None is not an allow value", '
|
|
'"error_type": "TypeError", "index": null, "track": "str", '
|
|
'"validator": "not_none_validator"}}')
|