Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
On/Off Switch for Fuzzyness #175
I would propose to support some sort of global mechanism that switches fuzzyness on and off.
The easiest solution (which I am using now) is to use a deterministic seed for the
I would be interested in other opinions, weather this is good practice or if I am missing something here.
Furthermore, I would propose to bake this into factory_boy. I think it should be possible to use a private random number generator in factory_boy, by using
Would you be interested in something like this? I am willing to put in some work to implement this.
The idea looks interesting, although I'm unsure about its execution.
On the other hand, being able to go "random yet repeatable" sounds like a great feature — if only to reproduce bugs spotted in CI.
How would the user set the random seed in your proposal? Through an environment variable, a call to some
Yes. I thought something along those lines. You are correct of course about the global state. I believe you could argue, however, that most of the arguments on why global state is bad (some are listed here) do not necessarily apply to a testing environment. The "fuzzyness" switch is a "real" global value, like an environment variable (run tests in deterministic or non-deterministic environment). If you want the behaviour I described, where the same code can be used in both cases, I think then, there is no other way. (Please correct me, if I'm wrong
If we really want to avoid global state, the only thing I can think of, is something like this:
field_name = factory.fuzzy.FuzzyText(deterministic=True)
In this case you have to explicitly have this in every field in your whole test suite, which is easily forgettable. And you'd still have to set the value through some global variable or another.