MarketSquare / MarketSquare/robotframework-faker

FakerLibrary cannot be initialized with multiple locales

Open
#42 1 comment 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
69
Forks
23
PR merge metrics
No merged PRs in 30d

Description

Faker Library supports initialization with multiple locales:
from faker import Faker
fake = Faker(['it_IT', 'en_US', 'ja_JP'])
for _ in range(10):
print(fake.name())

Whenever I try to initialize library with multiple locales it fails with error:
Error in file '/app/robot/keywords/InventoryImportKeywords.robot': Initializing test library 'FakerLibrary' with arguments [ locale=['ja_JP', 'de_DE', 'en_US'] ] failed: AttributeError: 'list' object has no attribute 'replace'
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/FakerLibrary/keywords.py", line 42, in __init__
self._fake = faker.factory.Factory.create(locale, providers)
File "/usr/local/lib/python3.8/site-packages/faker/factory.py", line 35, in create
locale = locale.replace('-', '_') if locale else DEFAULT_LOCALE

In factory.py file we always treat locale variable as a string with single argument and line:
locale = locale.replace('-', '_') if locale else DEFAULT_LOCALE
causes this issue

Would be super nice to have initialization with multiple locales implemented

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in FakerLibrary/keywords.py at the initialization call on line 42 and reproduce the Robot Framework failure with a locale list. Compare that call with faker.factory.Factory.create and factory.py's locale handling. Done means FakerLibrary initializes with multiple locales and the demonstrated name-generation usage works without the AttributeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.