Skip to content

Commit

Permalink
Add comments with former error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
gshank committed Jun 3, 2024
1 parent 79c9581 commit fefc73f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/unit/test_dataclass_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,31 @@ def test_validation():
dct = {"an_attr": "fubar"}
with pytest.raises(ValidationError) as excinfo:
SomeObject.validate(dct)
# former message: "'name' is a required property"
assert (
excinfo.value.msg
excinfo.value.message
== "Invalid value '{'an_attr': 'fubar'}': data must contain ['name'] properties"
)

dct = {"name": "testing", "an_int": "some_str"}
with pytest.raises(ValidationError) as excinfo:
SomeObject.validate(dct)
assert excinfo.value.msg == "Invalid value 'some_str': data.an_int must be integer"
# former message: "'some_str' is not of type 'integer'"
assert excinfo.value.message == "Invalid value 'some_str': data.an_int must be integer"

# Note: any field with multiple types (such as Optional[...]) will get the
# "cannot be validated by any definition" message.
dct = {"name": "testing", "an_enum": "four"}
with pytest.raises(ValidationError) as excinfo:
SomeObject.validate(dct)
# former message: "'four' is not valid under any of the given schemas"
assert (
excinfo.value.msg
excinfo.value.message
== "Invalid value 'four': data.an_enum cannot be validated by any definition"
)

dct = {"name": "testing", "a_bool": "True or False"}
with pytest.raises(ValidationError) as excinfo:
SomeObject.validate(dct)
assert excinfo.value.msg == "Invalid value 'True or False': data.a_bool must be boolean"
# former message: "'True or False' is not of type 'boolean'"
assert excinfo.value.message == "Invalid value 'True or False': data.a_bool must be boolean"

0 comments on commit fefc73f

Please sign in to comment.