-
Notifications
You must be signed in to change notification settings - Fork 400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a support for automated factory generation from a descriptive model #836
Comments
Oh, this feature would be awesome! If I can add my two cents regarding foreign keys: my team and I are used to manually creating generators for our models (which we want to stop doing XD). What has worked well for us is to only generate the required fields (that applies to FKs too). That means that every optional/nullable field will be set to About the integration with the ORM factories, I would make it integrated, possibly with a Edit: the library below does something like this. It could be looked at as inspiration, an example, or previous experience in implementing this. |
Hi, I would like to share a very alpha and simple PoC to generate a factory for dataclasses. https://gist.github.com/mgaitan/dcbe08bf44a5af696f2af752624ac11b it respects defaults, support builtin types, basic relationships, list/tuples/set, enums and email as a particular case based on the attribute name. |
…l): Automatically generate a factory from a pydantic model Sadly [it's not yet supported](FactoryBoy/factory_boy#869), [it will at some point though](FactoryBoy/factory_boy#836). If you're interested in following this path, you can start with [mgaitan snippet](https://gist.github.com/mgaitan/dcbe08bf44a5af696f2af752624ac11b) for dataclasses. feat(python_snippets#Make a flat list of lists with a list comprehension): Make a flat list of lists with a list comprehension There is no nice way to do it :(. The best I've found is: ```python t = [[1, 2, 3], [4, 5, 6], [7], [8, 9]] flat_list = [item for sublist in t for item in sublist] ``` feat(kubernetes_jobs#Manually creating a job from a cronjob): Manually creating a job from a cronjob ```bash kubectl create job {{ job_name }} -n {{ namespace }} \ --from=cronjobs/{{ cronjob_name}} ``` feat(pyment): Introduce Pyment [Pyment](https://github.com/dadadel/pyment) is a python3 program to automatically create, update or convert docstrings in existing Python files, managing several styles. As of 2021-11-17, the program is not production ready yet for me, I've tested it in one of my projects and found some bugs that needed to be fixed before it's usable. Despite the number of stars, it looks like the development pace has dropped dramatically, so it needs our help to get better :).
I'm brand new to Factory Boy, and I just want to share that as a Django user with dozens of models and hundreds of fields, I'm quite surprised that Factory Boy doesn't have a way of inspecting a model/dataclass/etc and generate reasonable fakers for each field. I've been reading docs for an hour or two, and it's only after I began working with the code I'm realizing I'm going to have to define Onwards with my explorations, but kinda bummed. |
Don't have too much experience with it myself yet, but at first glance the Pydantic ecosystem seems to be good for this kind of stuff. Might need a little up front investment. Check out https://github.com/Goldziher/pydantic-factories |
This issue will be used as the discussion basis for the automated factory generation feature.
The problem
Many libraries (ORMs, API schema languages,
dataclasses.dataclass
) provide a way to describe the fields of a class and their types.In those cases, it is cumbersome to have to add all the declarations manually; it would be great if factory_boy could provide a set of default declarations from an introspection of the class:
The typical example would be:
Existing work
Design constraints
Developer experience
make_factory
;factory.Faker
to use the field name as a hint (e.g callingfactory.Faker("user_name")
for a field calledusername
).Library integration
Factory
subclass, or through a customFactoryOptions
;DjangoModelFactory
; project B should be able to leverage it intoAutoDjangoModelFactory
)Open questions
DjangoModelFactory
/SQLAlchemyModelFactory
, or provide as extra classes?The text was updated successfully, but these errors were encountered: