You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This error is raised when the following code is called in a Django test case:
fromdjango_fakerimportFakerpopulator=Faker.getPopulator()
populator.addEntity(User, 2)
# Task contains a foreign key to a User objectpopulator.addEntity(Task, 5)
models=populator.execute()
Relevant stacktrace
Traceback (most recent call last):
File "/Users/ben/PycharmProjects/mistreatment/tasks/tests.py", line 14, in setUp
models = populator.execute()
File "/usr/local/lib/python3.6/site-packages/django_faker/populator.py", line 163, in execute
insertedEntities[klass].append( self.entities[klass].execute(using, insertedEntities) )
File "/usr/local/lib/python3.6/site-packages/django_faker/populator.py", line 104, in execute
value = format(insertedEntities) if hasattr(format,'__call__') else format
File "/usr/local/lib/python3.6/site-packages/django_faker/guessers.py", line 23, in<lambda>if name in ('username','login','nickname'): return lambda x:generator.userName()
File "/usr/local/lib/python3.6/site-packages/faker/providers/Internet.py", line 57, in userName
return self.bothify( self.generator.parse(format) ).lower()
File "/usr/local/lib/python3.6/site-packages/faker/providers/__init__.py", line 82, in bothify
return BaseProvider.lexify( BaseProvider.numerify( text ) )
File "/usr/local/lib/python3.6/site-packages/faker/providers/__init__.py", line 72, in lexify
return re.sub( r'\?', lambda x: BaseProvider.randomLetter(), text )
File "/usr/local/Cellar/python3/3.6.0_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/re.py", line 191, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "/usr/local/lib/python3.6/site-packages/faker/providers/__init__.py", line 72, in<lambda>return re.sub( r'\?', lambda x: BaseProvider.randomLetter(), text )
File "/usr/local/lib/python3.6/site-packages/faker/providers/__init__.py", line 35, in randomLetter
return random.choice( string.letters )
AttributeError: module 'string' has no attribute 'letters'
If the test is run 5 times it will only error 3 or 4 times it is run - which makes it even more confusing. Any idea what is going on here? Thanks.
The text was updated successfully, but these errors were encountered:
hey I'm not dealing with django yet but i had the same issue today when i was working with old project
module string has changes in python3
in python 2 'string.letters' was working fine
but in python 3 you need to add 'string.ascii_letters'
in your case probably you need to edit File "/usr/local/lib/python3.6/site-packages/faker/providers/init.py", line 35
in return random.choice( string.letters )
to
return random.choice( string.ascii_letters )
This error is raised when the following code is called in a Django test case:
Relevant stacktrace
If the test is run 5 times it will only error 3 or 4 times it is run - which makes it even more confusing. Any idea what is going on here? Thanks.
The text was updated successfully, but these errors were encountered: