Can Factory Boy auto generate Django model field values like Model Mommy does?
Asked Answered
A

1

11

By using Model Mommy, you don't have to set every Model field you use, Model Mommy will automatically set them for you.

but in Factory Boy, if you want to use some field in the test, you have to explicitly set the value for them in ModelFactory class.

My question is: Can Factory Boy auto generate Model field values like Model Mommy does?

Automotive answered 22/2, 2016 at 3:37 Comment(0)
P
11

No, Factory Boy does not currently have a way to generate values based on the attribute types defined on the database model without having to define a Factory Boy generator of some sort.

Sounds like a good feature request however.

Prerequisite answered 22/2, 2016 at 17:33 Comment(4)
There is django-factory_boy, however. (Yes: one dash, one underscore.) It aims at building basic factories automatically for Django ORM model classes. pypi.python.org/pypi/django-factory_boyBeverleebeverley
Hi, Lutz Prechelt, Can django-factory_boy automatically self define Model Factory?Automotive
Does not seem to do that @GoTop. Seems to only do it for some of the built in models. :-(Meneses
There's an open issue for this here: github.com/FactoryBoy/factory_boy/issues/836Gantt

© 2022 - 2024 — McMap. All rights reserved.