(py_and_json: PyAndJson)
| 54 | |
| 55 | |
| 56 | def 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') |
nothing calls this directly
no test coverage detected