Skip to content

Commit

Permalink
improve test
Browse files Browse the repository at this point in the history
  • Loading branch information
chan-vince committed Mar 26, 2024
1 parent ba177ef commit f42b70a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tests/test_main.py
Expand Up @@ -3161,12 +3161,16 @@ class Parent:

# When inheriting from the parent class, as long as the field is not defined at all, there should be no warning
# about shadowed fields.
with warnings.catch_warnings():
warnings.simplefilter('error')
with warnings.catch_warnings(record=True) as captured_warnings:
# Start capturing all warnings
warnings.simplefilter('always')

class ChildWithoutRedefinedField(BaseModel, Parent):
pass

# Check that no warnings were captured
assert len(captured_warnings) == 0

# But when inheriting from the parent class and a parent field is redefined, a warning should be raised about
# shadowed fields irrespective of whether it is defined with a type that is still compatible or narrower, or
# with a different default that is still compatible with the type definition.
Expand Down

0 comments on commit f42b70a

Please sign in to comment.