Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix xfailed test related to TypedDict and alias_generator #6940

Merged
merged 2 commits into from Aug 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/test_types_typeddict.py
Expand Up @@ -48,7 +48,7 @@ class TestTypedDict(TypedDictAll):
foo: str

if sys.version_info < (3, 12) and TypedDictAll.__module__ == 'typing':
pytest.skip('typing.TypedDict does not track required keys correctly on Python < 3.11')
pytest.skip('typing.TypedDict does not support all pydantic features in Python < 3.12')

if hasattr(TestTypedDict, '__required_keys__'):
return TypedDictAll
Expand Down Expand Up @@ -710,18 +710,18 @@ class RecursiveGenTypedDict(TypedDict, Generic[T]):
]


@pytest.mark.xfail(reason='Needs https://github.com/pydantic/pydantic/pull/5944')
def test_typeddict_alias_generator(TypedDict):
def alias_generator(name: str) -> str:
return 'alias_' + name

class MyDict(TypedDict):
__pydantic_config__ = ConfigDict(alias_generator=alias_generator, extra='forbid')
foo: str

class Model(BaseModel):
d: MyDict

ta = TypeAdapter(MyDict, config=ConfigDict(alias_generator=alias_generator))
ta = TypeAdapter(MyDict)
model = ta.validate_python({'alias_foo': 'bar'})

assert model['foo'] == 'bar'
Expand Down