From 57be4ac78b1213928a83079d298bafcc93e69483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20Ar=C8=9B=C4=83ri=C8=99i?= Date: Sat, 18 Jul 2015 14:30:50 +0100 Subject: add a way to add custom providers to Faker factory_boy wraps faker and it stores Faker generators in a 'private' _FAKER_REGISTRY class attribute dict. There needs to be a way to extend the Faker generators with additional custom providers (without having to access _FAKER_REGISTRY directly). This commit adds a (factory_boy) Faker.add_provider class method which calls Faker's own `add_provider` method on internally stored (via _FAKER_REGISTRY) Faker generators. --- factory/faker.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'factory') diff --git a/factory/faker.py b/factory/faker.py index 10a0cba..5411985 100644 --- a/factory/faker.py +++ b/factory/faker.py @@ -94,3 +94,8 @@ class Faker(declarations.OrderedDeclaration): cls._FAKER_REGISTRY[locale] = faker.Faker(locale=locale) return cls._FAKER_REGISTRY[locale] + + @classmethod + def add_provider(cls, provider, locale=None): + """Add a new Faker provider for the specified locale""" + cls._get_faker(locale).add_provider(provider) -- cgit v1.2.3