Skip to content

Commit 0f17e03

Browse files
committed
Merged in [18020] from rjsparks@nostrum.com:
Construct Faker objects used for person name generation only once. Results in a roughly 20% speedup of the test-suite. - Legacy-Id: 18023 Note: SVN reference [18020] has been migrated to Git commit c60cc1b
2 parents 820e30d + c60cc1b commit 0f17e03

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

ietf/person/factories.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,20 @@
2424

2525
fake = faker.Factory.create()
2626

27-
def random_faker():
27+
def setup():
28+
global acceptable_fakers
2829
# The transliteration of some arabic and devanagari names introduces
2930
# non-alphabetic characgters that don't work with the draft author
3031
# extraction code, and also don't seem to match the way people with arabic
3132
# names romanize arabic names. Exlude those locales from name generation
3233
# in order to avoid test failures.
3334
locales = set( [ l for l in faker.config.AVAILABLE_LOCALES if not (l.startswith('ar_') or l.startswith('sg_')) ] )
34-
return faker.Faker(random.sample(locales, 1)[0])
35+
acceptable_fakers = [faker.Faker(locale) for locale in locales]
36+
setup()
37+
38+
def random_faker():
39+
global acceptable_fakers
40+
return random.sample(acceptable_fakers, 1)[0]
3541

3642
class UserFactory(factory.DjangoModelFactory):
3743
class Meta:

0 commit comments

Comments
 (0)