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 test failures with pytest-8.0.0 due to pytest.warns() starting to work inside pytest.raises() #8678

Merged
merged 2 commits into from Feb 6, 2024
Merged
Show file tree
Hide file tree
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
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