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.

Global seeding does not work as expected

See original GitHub issue

Consider the following code:

import unittest
import random

from mimesis import Food

class Test(unittest.TestCase):
    def test_food(self):
        f = Food("en")
        print(">>", f.dish())

if __name__ == "__main__":
    random.seed("123")
    unittest.main()

I would expect that for consecutive runs the same dish is printed but it’s not:

>> Macaroni and Cheese
.
----------------------------------------------------------------------
Ran 1 test in 0.001s

OK

Press ENTER or type command to continue
>> Ploye
.
----------------------------------------------------------------------
Ran 1 test in 0.001s

OK

The question now is whether that is expected behavior? I know there is a specific seed for each Provider. Because I find it a bit annoying, requiring me to jump a few more hoops to get this under test.

>> python --version
Python 3.5.3
>> pip freeze|grep mime
mimesis==1.0.4

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kairichardcommented, Jan 7, 2018

@duckyou Thanks for effort you put into answering my question. Now I feel a bit ashamed noticing that my initial example is a bit misleading. I am using your awesome lib to produce names for things and I have an integration test that verify things get names. What I wanted to do is hardwire the test output. Something like this:

import unittest
import random

from service import App

class Test(unittest.TestCase):
    def test_names(self):
        result = App.create_thing()
        self.assertEqual(result.name, "ice-cream")

if __name__ == "__main__":
    random.seed("123")
    unittest.main()

HTH. What I am currently doing is seeding via os.env somewhere in service which is ok for now. Thanks again for answering my questions.

1reaction
lk-geimfaricommented, Jan 7, 2018

@duckyou Can you advise anything, please?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Seeding the generator in Python's "faker" module not working ...
This is fine, but it means that the second faker is pulling a global random number, so it is the same as if...
Read more >
Availability Group Direct Seeding: How to fix a database that ...
This post covers two scenarios. You either created a database, and the sync failed for some reason, or a database stopped syncing.
Read more >
Data Seeding - Understanding Scenario Setup - Planful
If no account mapping, Actual data is seeded. Calculated Lines without Account Mapping - Formula and result seed from Seed Data From scenario ......
Read more >
Depressing Study Shows a Big Issue With Using Cloud ...
The idea of seeding clouds with an injection of light-reflecting particles to reflect sunlight back into space – thereby 'cooling' the planet – ......
Read more >
Data Seeding - EF Core - Microsoft Learn
Data seeding is the process of populating a database with an initial set of data. There are several ways this can be accomplished...
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