MCPcopy
hub / github.com/pydantic/pydantic / test_annotated_before_validator_called_once

Function test_annotated_before_validator_called_once

tests/test_dataclasses.py:2847–2863  ·  view source on GitHub ↗
(decorator1)

Source from the content-addressed store, hash-verified

2845
2846@pytest.mark.parametrize('decorator1', **dataclass_decorators())
2847def test_annotated_before_validator_called_once(decorator1):
2848 count = 0
2849
2850 def convert(value: int) -> str:
2851 nonlocal count
2852 count += 1
2853 return str(value)
2854
2855 IntToStr = Annotated[str, BeforeValidator(convert)]
2856
2857 @decorator1
2858 class A:
2859 a: IntToStr
2860
2861 assert count == 0
2862 TypeAdapter(A).validate_python({'a': 123})
2863 assert count == 1
2864
2865
2866def test_is_pydantic_dataclass():

Callers

nothing calls this directly

Calls 3

BeforeValidatorClass · 0.90
TypeAdapterClass · 0.90
validate_pythonMethod · 0.45

Tested by

no test coverage detected