Skip to content

Commit

Permalink
Update another test
Browse files Browse the repository at this point in the history
  • Loading branch information
dmontagu committed Mar 24, 2023
1 parent 5c76a40 commit cde3565
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions tests/test_generics.py
Expand Up @@ -32,7 +32,16 @@
from pydantic_core import core_schema
from typing_extensions import Annotated, Literal, OrderedDict

from pydantic import BaseModel, Field, Json, PositiveInt, ValidationError, ValidationInfo, root_validator
from pydantic import (
BaseModel,
Field,
Json,
PositiveInt,
PydanticUserError,
ValidationError,
ValidationInfo,
root_validator,
)
from pydantic._internal._core_utils import collect_invalid_schemas
from pydantic._internal._generics import (
_GENERIC_TYPES_CACHE,
Expand Down Expand Up @@ -209,15 +218,22 @@ class Result(BaseModel, Generic[T]):
assert 'other' not in Result.model_fields


# TODO: Replace this test with a test that ensures the same warning message about non-annotated fields is raised
# for generic and non-generic models. Requires https://github.com/pydantic/pydantic/issues/5014
@pytest.mark.xfail(reason='working on V2 - non-annotated fields - issue #5014')
def test_non_annotated_field():
T = TypeVar('T')

with pytest.raises(PydanticUserError, match='A non-annotated attribute was detected: `other = True`'):

class Result(BaseModel, Generic[T]):
data: T
other = True


def test_non_generic_field():
T = TypeVar('T')

class Result(BaseModel, Generic[T]):
data: T
other = True
other: bool = True

assert 'other' in Result.model_fields
assert 'other' in Result[int].model_fields
Expand Down

0 comments on commit cde3565

Please sign in to comment.