Skip to content

Commit

Permalink
move xfail from module to individual failing tests (#4843)
Browse files Browse the repository at this point in the history
* move xfail from module to individual failing tests

* missed a test. fixed formatting.

* removed xfail mark from a passing test
  • Loading branch information
jimkring committed Dec 21, 2022
1 parent b221981 commit a96794d
Show file tree
Hide file tree
Showing 15 changed files with 533 additions and 29 deletions.
20 changes: 18 additions & 2 deletions tests/test_aliases.py
Expand Up @@ -7,9 +7,8 @@
from pydantic import BaseConfig, BaseModel, Extra, ValidationError
from pydantic.fields import Field

pytestmark = pytest.mark.xfail(reason='working on V2', strict=False)


@pytest.mark.xfail(reason='working on V2')
def test_alias_generator():
def to_camel(string: str):
return ''.join(x.capitalize() for x in string.split('_'))
Expand All @@ -28,6 +27,7 @@ class Config:
assert v.dict(by_alias=True) == data


@pytest.mark.xfail(reason='working on V2')
def test_alias_generator_with_field_schema():
def to_upper_case(string: str):
return string.upper()
Expand All @@ -47,6 +47,7 @@ class Config:
assert m.dict(by_alias=True) == data


@pytest.mark.xfail(reason='working on V2')
def test_alias_generator_wrong_type_error():
def return_bytes(string):
return b'not a string'
Expand All @@ -62,6 +63,7 @@ class Config:
assert str(e.value) == "Config.alias_generator must return str, not <class 'bytes'>"


@pytest.mark.xfail(reason='working on V2')
def test_infer_alias():
class Model(BaseModel):
a = 'foobar'
Expand All @@ -75,6 +77,7 @@ class Config:
)


@pytest.mark.xfail(reason='working on V2')
def test_alias_error():
class Model(BaseModel):
a = 123
Expand All @@ -91,6 +94,7 @@ class Config:
]


@pytest.mark.xfail(reason='working on V2')
def test_annotation_config():
class Model(BaseModel):
b: float
Expand All @@ -105,6 +109,7 @@ class Config:
assert Model(foobar='123').b == 123.0


@pytest.mark.xfail(reason='working on V2')
def test_alias_camel_case():
class Model(BaseModel):
one_thing: int
Expand All @@ -124,6 +129,7 @@ def get_field_info(cls, name):
assert v == {'one_thing': 123, 'another_thing': 321}


@pytest.mark.xfail(reason='working on V2')
def test_get_field_info_inherit():
class ModelOne(BaseModel):
class Config(BaseConfig):
Expand All @@ -146,6 +152,7 @@ class Config:
assert v == {'one_thing': 123, 'another_thing': 321, 'third_thing': 1}


@pytest.mark.xfail(reason='working on V2')
def test_pop_by_field_name():
class Model(BaseModel):
last_updated_by: Optional[str] = None
Expand All @@ -164,6 +171,7 @@ class Config:
]


@pytest.mark.xfail(reason='working on V2')
def test_alias_child_precedence():
class Parent(BaseModel):
x: int
Expand All @@ -181,6 +189,7 @@ class Config:
assert Child.__fields__['x'].alias == 'x2'


@pytest.mark.xfail(reason='working on V2')
def test_alias_generator_parent():
class Parent(BaseModel):
x: int
Expand All @@ -204,6 +213,7 @@ def alias_generator(cls, f_name):
assert Child.__fields__['x'].alias == 'x2'


@pytest.mark.xfail(reason='working on V2')
def test_alias_generator_on_parent():
class Parent(BaseModel):
x: bool = Field(..., alias='a_b_c')
Expand All @@ -225,6 +235,7 @@ class Child(Parent):
assert Child.__fields__['z'].alias == 'Z'


@pytest.mark.xfail(reason='working on V2')
def test_alias_generator_on_child():
class Parent(BaseModel):
x: bool = Field(..., alias='abc')
Expand All @@ -243,6 +254,7 @@ def alias_generator(x):
assert [f.alias for f in Child.__fields__.values()] == ['abc', 'Y', 'Z']


@pytest.mark.xfail(reason='working on V2')
def test_low_priority_alias():
class Parent(BaseModel):
x: bool = Field(..., alias='abc', alias_priority=1)
Expand All @@ -261,6 +273,7 @@ def alias_generator(x):
assert [f.alias for f in Child.__fields__.values()] == ['X', 'Y', 'Z']


@pytest.mark.xfail(reason='working on V2')
def test_low_priority_alias_config():
class Parent(BaseModel):
x: bool
Expand All @@ -282,6 +295,7 @@ def alias_generator(x):
assert [f.alias for f in Child.__fields__.values()] == ['X', 'Y', 'Z']


@pytest.mark.xfail(reason='working on V2')
def test_field_vs_config():
class Model(BaseModel):
x: str = Field(..., alias='x_on_field')
Expand All @@ -294,6 +308,7 @@ class Config:
assert [f.alias for f in Model.__fields__.values()] == ['x_on_field', 'y_on_config', 'z']


@pytest.mark.xfail(reason='working on V2')
def test_alias_priority():
class Parent(BaseModel):
a: str = Field(..., alias='a_field_parent')
Expand Down Expand Up @@ -340,6 +355,7 @@ def alias_generator(x):
]


@pytest.mark.xfail(reason='working on V2')
def test_empty_string_alias():
class Model(BaseModel):
empty_string_key: int = Field(alias='')
Expand Down
18 changes: 16 additions & 2 deletions tests/test_construction.py
Expand Up @@ -6,8 +6,6 @@
from pydantic import BaseModel, Field, PrivateAttr
from pydantic.fields import Undefined

pytestmark = pytest.mark.xfail(reason='working on V2', strict=False)


class Model(BaseModel):
a: float
Expand Down Expand Up @@ -95,6 +93,7 @@ class ModelTwo(BaseModel):
return ModelTwo


@pytest.mark.xfail(reason='working on V2')
def test_deep_copy(ModelTwo):
m = ModelTwo(a=24, d=Model(a='12'))
m.__foo__ = {'new value'}
Expand All @@ -110,6 +109,7 @@ def test_deep_copy(ModelTwo):
assert m.__foo__ is not m2.__foo__


@pytest.mark.xfail(reason='working on V2')
def test_copy_exclude(ModelTwo):
m = ModelTwo(a=24, d=Model(a='12'))
m2 = m.copy(exclude={'b'})
Expand All @@ -126,6 +126,7 @@ def test_copy_exclude(ModelTwo):
assert m != m2


@pytest.mark.xfail(reason='working on V2')
def test_copy_include(ModelTwo):
m = ModelTwo(a=24, d=Model(a='12'))
m2 = m.copy(include={'a'})
Expand All @@ -137,6 +138,7 @@ def test_copy_include(ModelTwo):
assert m != m2


@pytest.mark.xfail(reason='working on V2')
def test_copy_include_exclude(ModelTwo):
m = ModelTwo(a=24, d=Model(a='12'))
m2 = m.copy(include={'a', 'b', 'c'}, exclude={'c'})
Expand All @@ -145,6 +147,7 @@ def test_copy_include_exclude(ModelTwo):
assert set(m2.dict().keys()) == {'a', 'b'}


@pytest.mark.xfail(reason='working on V2')
def test_copy_advanced_exclude():
class SubSubModel(BaseModel):
a: str
Expand All @@ -168,6 +171,7 @@ class Model(BaseModel):
assert m2.dict() == {'f': {'c': 'foo'}}


@pytest.mark.xfail(reason='working on V2')
def test_copy_advanced_include():
class SubSubModel(BaseModel):
a: str
Expand All @@ -191,6 +195,7 @@ class Model(BaseModel):
assert m2.dict() == {'e': 'e', 'f': {'d': [{'a': 'c', 'b': 'e'}]}}


@pytest.mark.xfail(reason='working on V2')
def test_copy_advanced_include_exclude():
class SubSubModel(BaseModel):
a: str
Expand All @@ -209,6 +214,7 @@ class Model(BaseModel):
assert m2.dict() == {'f': {'d': [{'a': 'c', 'b': 'e'}]}}


@pytest.mark.xfail(reason='working on V2')
def test_copy_update(ModelTwo):
m = ModelTwo(a=24, d=Model(a='12'))
m2 = m.copy(update={'a': 'different'})
Expand All @@ -220,6 +226,7 @@ def test_copy_update(ModelTwo):
assert m != m2


@pytest.mark.xfail(reason='working on V2')
def test_copy_update_unset():
class Foo(BaseModel):
foo: Optional[str]
Expand All @@ -228,6 +235,7 @@ class Foo(BaseModel):
assert Foo(foo='hello').copy(update={'bar': 'world'}).json(exclude_unset=True) == '{"foo": "hello", "bar": "world"}'


@pytest.mark.xfail(reason='working on V2')
def test_copy_set_fields(ModelTwo):
m = ModelTwo(a=24, d=Model(a='12'))
m2 = m.copy()
Expand All @@ -249,6 +257,7 @@ def test_simple_pickle():
assert m.__fields__ == m2.__fields__


@pytest.mark.xfail(reason='working on V2')
def test_recursive_pickle(ModelTwo):
m = ModelTwo(a=24, d=Model(a='123.45'))
m2 = pickle.loads(pickle.dumps(m))
Expand All @@ -260,6 +269,7 @@ def test_recursive_pickle(ModelTwo):
assert m.__foo__ == m2.__foo__


@pytest.mark.xfail(reason='working on V2')
def test_pickle_undefined(ModelTwo):
m = ModelTwo(a=24, d=Model(a='123.45'))
m2 = pickle.loads(pickle.dumps(m))
Expand All @@ -270,6 +280,7 @@ def test_pickle_undefined(ModelTwo):
assert not hasattr(m3, '__foo__')


@pytest.mark.xfail(reason='working on V2')
def test_copy_undefined(ModelTwo):
m = ModelTwo(a=24, d=Model(a='123.45'))
m2 = m.copy()
Expand All @@ -280,6 +291,7 @@ def test_copy_undefined(ModelTwo):
assert not hasattr(m3, '__foo__')


@pytest.mark.xfail(reason='working on V2')
def test_immutable_copy_with_allow_mutation():
class Model(BaseModel):
a: int
Expand Down Expand Up @@ -321,6 +333,7 @@ def test_pickle_fields_set():
assert m2.dict(exclude_unset=True) == {'a': 24}


@pytest.mark.xfail(reason='working on V2')
def test_copy_update_exclude():
class SubModel(BaseModel):
a: str
Expand Down Expand Up @@ -357,6 +370,7 @@ class X(BaseModel):
assert y.deep['deep_thing'] == [1, 2, 3]


@pytest.mark.xfail(reason='working on V2')
def test_construct_default_factory():
class Model(BaseModel):
foo: List[int] = Field(default_factory=list)
Expand Down
15 changes: 13 additions & 2 deletions tests/test_create_model.py
Expand Up @@ -6,9 +6,8 @@
from pydantic.fields import ModelPrivateAttr
from pydantic.generics import GenericModel

pytestmark = pytest.mark.xfail(reason='working on V2', strict=False)


@pytest.mark.xfail(reason='working on V2')
def test_create_model():
model = create_model('FooModel', foo=(str, ...), bar=123)
assert issubclass(model, BaseModel)
Expand All @@ -20,6 +19,7 @@ def test_create_model():
assert model.__module__ == 'pydantic.main'


@pytest.mark.xfail(reason='working on V2')
def test_create_model_usage():
model = create_model('FooModel', foo=(str, ...), bar=123)
m = model(foo='hello')
Expand Down Expand Up @@ -70,6 +70,7 @@ def test_config_and_base():
create_model('FooModel', __config__=BaseModel.Config, __base__=BaseModel)


@pytest.mark.xfail(reason='working on V2')
def test_inheritance():
class BarModel(BaseModel):
x = 1
Expand All @@ -81,6 +82,7 @@ class BarModel(BaseModel):
assert m.dict() == {'bar': 123, 'foo': 'a', 'x': 4, 'y': 2}


@pytest.mark.xfail(reason='working on V2')
def test_custom_config():
class Config:
fields = {'foo': 'api-foo-field'}
Expand All @@ -92,6 +94,7 @@ class Config:
model(foo=654)


@pytest.mark.xfail(reason='working on V2')
def test_custom_config_inherits():
class Config(BaseModel.Config):
fields = {'foo': 'api-foo-field'}
Expand All @@ -113,6 +116,7 @@ class Config(BaseModel.Config):
model(bar=654)


@pytest.mark.xfail(reason='working on V2')
def test_inheritance_validators():
class BarModel(BaseModel):
@validator('a', check_fields=False)
Expand All @@ -128,6 +132,7 @@ def check_a(cls, v):
model(a='something else')


@pytest.mark.xfail(reason='working on V2')
def test_inheritance_validators_always():
class BarModel(BaseModel):
@validator('a', check_fields=False, always=True)
Expand All @@ -144,6 +149,7 @@ def check_a(cls, v):
model(a='something else')


@pytest.mark.xfail(reason='working on V2')
def test_inheritance_validators_all():
class BarModel(BaseModel):
@validator('*')
Expand All @@ -154,6 +160,7 @@ def check_all(cls, v):
assert model(a=2, b=6).dict() == {'a': 4, 'b': 12}


@pytest.mark.xfail(reason='working on V2')
def test_funky_name():
model = create_model('FooModel', **{'this-is-funky': (int, ...)})
m = model(**{'this-is-funky': '123'})
Expand All @@ -165,6 +172,7 @@ def test_funky_name():
]


@pytest.mark.xfail(reason='working on V2')
def test_repeat_base_usage():
class Model(BaseModel):
a: str
Expand Down Expand Up @@ -202,6 +210,7 @@ class A(BaseModel):
assert A.__fields__[field_name].default == DynamicA.__fields__[field_name].default


@pytest.mark.xfail(reason='working on V2')
def test_config_field_info_create_model():
class Config:
fields = {'a': {'description': 'descr'}}
Expand All @@ -213,6 +222,7 @@ class Config:
assert m2.schema()['properties'] == {'a': {'title': 'A', 'description': 'descr', 'type': 'string'}}


@pytest.mark.xfail(reason='working on V2')
def test_generics_model():
T = TypeVar('T')

Expand All @@ -227,6 +237,7 @@ class TestGenericModel(GenericModel):
assert result.__config__.orm_mode is True


@pytest.mark.xfail(reason='working on V2')
@pytest.mark.parametrize('base', [ModelPrivateAttr, object])
def test_set_name(base):
calls = []
Expand Down

0 comments on commit a96794d

Please sign in to comment.