From 3833ff0f0ffacdbfa08ca68559aa50d4904abfc9 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 29 Aug 2017 21:40:22 -0400 Subject: [PATCH] DOC: add section on setting random number seeds --- doc/devel/testing.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/devel/testing.rst b/doc/devel/testing.rst index 9d4e29d35c59..7dfb9092cdf4 100644 --- a/doc/devel/testing.rst +++ b/doc/devel/testing.rst @@ -139,6 +139,23 @@ execution (such as created figures or modified rc params). The pytest fixture :func:`~matplotlib.testing.conftest.mpl_test_settings` will automatically clean these up; there is no need to do anything further. +Random data in tests +-------------------- + +Random data can is a very convenient way to generate data for examples, +however the randomness is problematic for testing (as the tests +must be deterministic!). To work around this set the seed in each test. +For numpy use:: + + import numpy as np + np.random.seed(19680801) + +and Python's random number generator:: + + import random + random.seed(19680801) + +The seed is John Hunter's birthday. Writing an image comparison test --------------------------------