Change default faker locale in factory_boy
See original GitHub issueHow can I set the default locale in Python’s factory_boy for all of my Factories?
In docs says that one should set it with factory.Faker.override_default_locale but that does nothing to my fakers…
import factory
from app.models import Example
from custom_fakers import CustomFakers
# I use custom fakers, this indeed are added
factory.Faker.add_provider(CustomFakers)
# But not default locales
factory.Faker.override_default_locale('es_ES')
class ExampleFactory(factory.django.DjangoModelFactory):
class Meta:
model = Example
name = factory.Faker('first_name')
>>> from example import ExampleFactory
>>> e1 = ExampleFactory()
>>> e1.name
>>> u'Chad'
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Change default faker locale in factory_boy - Stack Overflow
In docs says that one should set it with factory.Faker.override_default_locale but that does nothing to my fakers... import factory from app.
Read more >[Answered]-Change default faker locale in factory_boy-django
In docs says that one should set it with factory.Faker.override_default_locale but that does nothing to my fakers... import factory from app.models import ...
Read more >Reference — Factory Boy stable documentation
Change the default strategy of the decorated Factory to the chosen strategy : ... In order to easily define realistic-looking factories, use the...
Read more >Locale en_US — Faker 15.3.4 documentation
If safe_mode is True (default), this method performs another set of conversions to guarantee that the UPC-E barcodes generated can be converted to...
Read more >factory.faker — Factory Boy stable documentation
Faker ('name') """ import contextlib import faker import faker.config from . import ... Args: provider (str): the name of the Faker field locale...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
See workaround here.
So, let’s look at the different situations where one might want to change the default locale:
with override_default_locale():
@override_default_locale()
@override_default_locale()
might not be enough hereFor the last two cases, we’ll have to look into the program setup:
with override_default_locale()
within the program’smain()
functionFor Django, I believe that the recommended mode is to:
DiscoverRunner
run_tests
function, to wrap the initial method inside awith override_default_locale()
TEST_RUNNER
to your class: