question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Faker returns one value when using multiple locales

See original GitHub issue
  • Faker version: 13.11
  • OS: Mac OS Monterey Computer: MacBook Pro (14-inch, 2021)

Brief summary of the issue goes here. If using multiple locales, faker only makes one choice. This only happens when you select multiple locales

Steps to reproduce

from faker import Faker

fake = Faker(["en_GB", "fr_FR", "en_IN"])
Faker.seed(0)
for _ in range(5):
    print(fake.date_time_this_year())

Expected behavior

returns

2022-03-16 19:22:23
2022-03-23 16:00:20
2022-01-08 20:40:15
2022-02-20 06:38:22
2022-04-10 06:42:46

Actual behavior

returns

2022-03-23 16:00:20
2022-03-23 16:00:20
2022-03-23 16:00:20
2022-03-23 16:00:20
2022-03-23 16:00:20

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
johntmyerscommented, Nov 21, 2022

@princelySid Yes good call. I just pushed a change. I think this test asserts two things:

1/ that the values are not all the same

2/ that the lists are the same between instances of Faker - which should confirm that nothing needs to be re-seeded on each call to a faker method

1reaction
johntmyerscommented, Nov 21, 2022

I made these changes: https://github.com/johntmyers/faker/commit/a264c268f81e803fa5ba6da3ca868be1da738b2c - which seems to work fine. I updated the test as well which basically makes sure that when seeding is used with multiple locales, you get consistent output for each method. I’m happy to open this as a PR but would still like to understand if there was some other intent that was missing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the Faker Class — Faker 15.3.4 documentation
Depending on the locale value passed, a new Faker instance will either operate in single locale mode or multiple locale mode. The value...
Read more >
Feat: Instantiate standalone Faker instance, import locales (or ...
The Faker constructor initializes locale to en , but seems to use an empty object as the default for locales . Proposed solution(s):....
Read more >
Get random locale with python Faker lib - Stack Overflow
If you want random entry for some locale - use multi locale mode and there are number of random functions like Faker.random_object_name ....
Read more >
Generating fake personal data in Python with faker
This post gives a quick example of using the faker package in Python to generate fake customer data.
Read more >
The faker.js tutorial - generating fake data in JavaScript with ...
The faker.js can generate fake data for various areas, including address, ... In the first example, we fake data related to user names....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found