Skip to content

Commit f129f23

Browse files
committed
add tests
1 parent c252431 commit f129f23

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/settings-library/src/settings_library/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
class DefaultFromEnvFactoryError(ValueError):
2424
def __init__(self, errors):
25-
super().__init__()
25+
super().__init__("Default could not be constructed")
2626
self.errors = errors
2727

2828

packages/settings-library/tests/test_base_w_postgres.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,24 @@ def test_parse_from_empty_envs(
120120

121121
S1, S2, S3, S4, S5 = model_classes_factory()
122122

123-
with pytest.raises(ValidationError):
123+
with pytest.raises(ValidationError, match="WEBSERVER_POSTGRES") as exc_info:
124124
S1()
125125

126+
validation_error = exc_info.value
127+
assert validation_error.error_count() == 1
128+
error = validation_error.errors()[0]
129+
assert error["type"] == "missing"
130+
assert error["input"] == {}
131+
126132
s2 = S2()
127133
assert s2.WEBSERVER_POSTGRES_NULLABLE_OPTIONAL is None
128134

129-
with pytest.raises(DefaultFromEnvFactoryError):
135+
with pytest.raises(DefaultFromEnvFactoryError) as exc_info:
130136
# NOTE: cannot have a default or assignment
131137
S3()
132138

139+
assert len(exc_info.value.errors) == 4, "Default could not be constructed"
140+
133141
# auto default factory resolves to None (because is nullable)
134142
s4 = S4()
135143
assert s4.WEBSERVER_POSTGRES_NULLABLE_DEFAULT_ENV is None

0 commit comments

Comments
 (0)