faif / python-patterns

A collection of design patterns/idioms in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

random seed does not take effect in doctest

qitianliang opened this issue · comments

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.

Hi,

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

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?

I'll work on this.