Skip to content

Commit

Permalink
Fix test failures with pytest-8.0.0 due to pytest.warns() starting …
Browse files Browse the repository at this point in the history
…to work inside `pytest.raises()` (#8678)
  • Loading branch information
mgorny committed Feb 6, 2024
1 parent b1bb24e commit 825a692
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
16 changes: 8 additions & 8 deletions pydantic/deprecated/class_validators.py
Expand Up @@ -109,6 +109,14 @@ def validator(
Callable: A decorator that can be used to decorate a
function to be used as a validator.
"""
warn(
'Pydantic V1 style `@validator` validators are deprecated.'
' You should migrate to Pydantic V2 style `@field_validator` validators,'
' see the migration guide for more details',
DeprecationWarning,
stacklevel=2,
)

if allow_reuse is True: # pragma: no cover
warn(_ALLOW_REUSE_WARNING_MESSAGE, DeprecationWarning)
fields = tuple((__field, *fields))
Expand All @@ -125,14 +133,6 @@ def validator(
code='validator-invalid-fields',
)

warn(
'Pydantic V1 style `@validator` validators are deprecated.'
' You should migrate to Pydantic V2 style `@field_validator` validators,'
' see the migration guide for more details',
DeprecationWarning,
stacklevel=2,
)

mode: Literal['before', 'after'] = 'before' if pre is True else 'after'

def dec(f: Any) -> _decorators.PydanticDescriptorProxy[Any]:
Expand Down
8 changes: 3 additions & 5 deletions tests/test_validators.py
Expand Up @@ -556,11 +556,9 @@ def test_use_no_fields():
class Model(BaseModel):
a: str

with pytest.warns(PydanticDeprecatedSince20, match=V1_VALIDATOR_DEPRECATION_MATCH):

@validator()
def checker(cls, v):
return v
@validator()
def checker(cls, v):
return v


def test_use_no_fields_field_validator():
Expand Down

0 comments on commit 825a692

Please sign in to comment.