question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Share faker generator with Factory Boy's faker registry

See original GitHub issue

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

import factory
from faker import Factory as FakerFactory

LOCALE = 'en-US'
fake = FakerFactory.create(locale=LOCALE)
factory.Faker._DEFAULT_LOCALE = LOCALE
factory.Faker._FAKER_REGISTRY[LOCALE] = fake

Extra notes

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
x-yuricommented, Jan 10, 2021

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.

1reaction
x-yuricommented, Jan 10, 2021

The only thing special about the faker in my projects, is setting the locale, adding custom providers, and also setting the faker seed.

Setting the locale: https://github.com/FactoryBoy/factory_boy/issues/407#issuecomment-754281399 https://github.com/FactoryBoy/factory_boy/pull/832

Adding providers: see the previous post.

Setting the seed: https://github.com/FactoryBoy/factory_boy/issues/833

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Share faker generator with Factory Boy's faker registry -
No documented way to share an existing faker generator with Factory Boy. Sometimes you might not always want to use the faker library...
Read more >
Locale en_US — Faker 15.3.4 documentation
Generate a random timezone (see faker.timezone for any args) and return as a python object usable as a tzinfo to datetime or other...
Read more >
FakerPHP / Faker
Faker is a PHP library that generates fake data for you. ... Use Faker\Factory::create() to create and initialize a faker generator, which can...
Read more >
How to use Faker from Factory_boy - python - Stack Overflow
You can use faker with factory_boy like this: class RandomUserFactory(factory.Factory): class Meta: model = models.User first_name = factory.
Read more >
fake news generator app
( Example : app brand cool kids ) Most people use the fake name generator and fake email generator for successful registration on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found