MCPcopy
hub / github.com/pydantic/pydantic / test_omit

Function test_omit

pydantic-core/tests/test_isinstance.py:56–73  ·  view source on GitHub ↗
(py_and_json: PyAndJson)

Source from the content-addressed store, hash-verified

54
55
56def test_omit(py_and_json: PyAndJson):
57 def omit(v, info):
58 if v == 'omit':
59 raise PydanticOmit
60 elif v == 'error':
61 raise ValueError('error')
62 else:
63 return v
64
65 v = py_and_json(core_schema.with_info_plain_validator_function(omit))
66 assert v.validate_test('foo') == 'foo'
67 if v.validator_type == 'python':
68 assert v.isinstance_test('foo') is True
69
70 if v.validator_type == 'python':
71 assert v.isinstance_test('error') is False
72 with pytest.raises(SchemaError, match='Uncaught Omit error, please check your usage of `default` validators.'):
73 v.validate_test('omit')

Callers

nothing calls this directly

Calls 3

py_and_jsonFunction · 0.85
validate_testMethod · 0.80
isinstance_testMethod · 0.80

Tested by

no test coverage detected