The defined model has 8 fields with some relatively complex annotations. The last field has an undefined forward annotation, that will fail to resolve on model rebuild. The benchmark is used to measure time spent in trying to rebuild a model knowing that it will fail when encountering t
(benchmark)
| 232 | |
| 233 | @pytest.mark.benchmark(group='model_schema_generation') |
| 234 | def test_failed_rebuild(benchmark): |
| 235 | """The defined model has 8 fields with some relatively complex annotations. |
| 236 | |
| 237 | The last field has an undefined forward annotation, that will fail to resolve on model rebuild. |
| 238 | The benchmark is used to measure time spent in trying to rebuild a model knowing that it will |
| 239 | fail when encountering the last field. |
| 240 | """ |
| 241 | fields: dict[str, Any] = { |
| 242 | f'f{i}': Annotated[Union[int, Annotated[str, Field(max_length=3)]], AfterValidator(lambda v: v)] |
| 243 | for i in range(8) |
| 244 | } |
| 245 | fields['f8'] = 'Undefined' |
| 246 | |
| 247 | ModelWithUndefinedAnnotation = create_model( # pyright: ignore[reportCallIssue] |
| 248 | 'ModelWithUndefinedAnnotation', |
| 249 | __base__=DeferredModel, |
| 250 | **fields, |
| 251 | ) |
| 252 | |
| 253 | benchmark(rebuild_model, ModelWithUndefinedAnnotation, raise_errors=False) |
| 254 | |
| 255 | |
| 256 | @pytest.mark.benchmark(group='model_schema_generation') |
nothing calls this directly
no test coverage detected