polyfactory
polyfactory copied to clipboard
Auto-register factories as pytest fixtures
It would be super handy to have some method that would easily create a fixture out of a factory. For example:
class SomeLongNamedModel(BaseModel):
id: UUID
@register_fixture # Or some better name?
class SomeLongNamedModelFactory(ModelFactory):
"""Factory to create SomeLongNameModel instances
Use this factory to generate SomeLongNameModels filled with random data
"""
__model__ = SomeLongNamedModel
And then
$ pytest --fixtures
# other output...
some_long_named_model_factory
Factory to create SomeLongNameModel instances
Use this factory to generate SomeLongNameModels filled with random data
This is following the model of pytest-factoryboy which automatically converts the PascalCase class names to be the snake_case equivalent for the fixtures.
Sure, this is a good suggestion. If you'd like to add this it would be a welcome addition.
I think I could try to implenment this recently.
Cool