Seeds for factories to reproduce #185

Closed
mihaicc opened this Issue Feb 17, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@mihaicc

mihaicc commented Feb 17, 2015

Need:

Given I use factories in my tests
And those factories generate random data for some fields
When I run a test which fails depending on the random generated data
Then I need to reproduce the test consistently to fix the problem

Deliverable:

A way of settings a global seed for the randoms to become fixed and being able to reproduce the error in the test constantly.

Solution:

  • One idea would to set the seed on random at first factory import
  • Print the seed so it appears in the log of the broken test
  • allow the seed to be set somewhere for next test run.

Notes:

  • Seed might not be enough, see difference between seed and getstate
  • This issue might not make sense if other libs except random are used. Or maybe the the principle should be abstracted to still apply.

rbarrois added a commit that referenced this issue Feb 18, 2015

Enable resetting factory.fuzzy's random generator (Closes #175, #185).
Users may now call ``factory.fuzzy.get_random_state()`` to retrieve
the current random generator's state (isolated from the one used in
Python's ``random``).

That state can then be reinjected with
``factory.fuzzy.set_random_state(state)``.
@rbarrois

This comment has been minimized.

Show comment
Hide comment
@rbarrois

rbarrois Feb 18, 2015

Member

Hi @mihaicc !

I've just added commit 97a8890 to enable this; factory.fuzzy now uses a separated random generator, with helpers to get/set its state.

How that state is used in one's test setup isn't managed by factory_boy, but this enables to print the current "state" before tests.

Member

rbarrois commented Feb 18, 2015

Hi @mihaicc !

I've just added commit 97a8890 to enable this; factory.fuzzy now uses a separated random generator, with helpers to get/set its state.

How that state is used in one's test setup isn't managed by factory_boy, but this enables to print the current "state" before tests.

@rbarrois rbarrois closed this Feb 18, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment