Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random seed does not take effect in doctest #376

Closed
qitianliang opened this issue Jun 11, 2021 · 3 comments · Fixed by #393
Closed

random seed does not take effect in doctest #376

qitianliang opened this issue Jun 11, 2021 · 3 comments · Fixed by #393
Labels

Comments

@qitianliang
Copy link

qitianliang commented Jun 11, 2021

Thanks for your awesome works on the pythonic design pattern, I'm reviewing some strategies in the design patterns. However, I tried your first abstract_factory.py
random. seed(1234) in the main function will not take effect in doctest random. choice(), and it returns fake random depend on machine time or some other kind of random parameter.
I tried to fix this problem by this

random.seed(1234)
shop = PetShop(random_animal)

then you can get the same result every time you rerun it.

@faif
Copy link
Owner

faif commented Jun 12, 2021

Hi,

Please open a pull request so that we can get the fix in, and you get credit for your contribution :)

@gyermolenko
Copy link
Contributor

maybe I misunderstand original message about

random. seed(1234) in the main function will not take effect in doctest random

but if I remove random.seed(1234)
running python patterns/creational/abstract_factory.py produces ***Test Failed*** 1 failures

(and it produces nothing if random.seed(1234) is at place). So I believe random.seed is there works out for deterministic output.

What output do you have?

@Mohamed-ElGemeie
Copy link

I'll work on this.

@faif faif closed this as completed in #393 Jul 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants