-
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
Share faker generator with Factory Boy's faker registry #554
Comments
That's indeed a limitation. Do you have some examples of things you run on those custom fakers? |
The only thing special about the faker in my projects, is setting the locale, adding custom providers, and also setting the faker seed. Nothing particularly special with my use case. It was mainly being able to use the custom providers, as I could have lived with the locale being wrong, and the seed not being the same. Here's an example of a couple of providers I wrote. The rest I can't share, as they're more sensitive (these aren't open source projects):
The seed stuff is useful for having a chance of replicating inconsistent test failures, as you can feed in the same seed, and hopefully the tests will fail in the same way. Personally I haven't needed to do this (yet), but it's something that could be useful:
|
I believe resolving #407 resolves this issue as well. Since this one was created in hope to work around the former. As it is you can add custom providers: import factory, faker
class MyProvider(faker.providers.BaseProvider):
def smth(self):
return self.random_element([1, 2, 3])
factory.Faker.add_provider(MyProvider) And set the seed. Although I believe it's poorly documented. And I'm going to file a corresponding issue. I can mention there anybody interested. |
Setting the locale: Adding providers: see the previous post. Setting the seed: |
Thank you. This is very useful. Seeing as the other tickets, cover it, I guess this can be closed then? |
The problem
No documented way to share an existing faker generator with Factory Boy. Sometimes you might not always want to use the faker library from Factory Boy's Faker class, so it would be nice if Factory Boy could share a common faker generator.
Proposed solution
Allow an easy way to attach an existing faker generator to Factory Boy. Perhaps something like
factory.Faker.attach_fake(faker_generator)
, assuming that's possible?Workaround
Extra notes
The text was updated successfully, but these errors were encountered: