Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a67b232

Browse filesBrowse files
authored
Merge pull request matplotlib#9123 from tacaswell/doc_test_random
DOC: add section on setting random number seeds
2 parents da06ed9 + 3833ff0 commit a67b232
Copy full SHA for a67b232

File tree

Expand file treeCollapse file tree

1 file changed

+17
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+17
-0
lines changed

‎doc/devel/testing.rst

Copy file name to clipboardExpand all lines: doc/devel/testing.rst
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ execution (such as created figures or modified rc params). The pytest fixture
139139
:func:`~matplotlib.testing.conftest.mpl_test_settings` will automatically clean
140140
these up; there is no need to do anything further.
141141

142+
Random data in tests
143+
--------------------
144+
145+
Random data can is a very convenient way to generate data for examples,
146+
however the randomness is problematic for testing (as the tests
147+
must be deterministic!). To work around this set the seed in each test.
148+
For numpy use::
149+
150+
import numpy as np
151+
np.random.seed(19680801)
152+
153+
and Python's random number generator::
154+
155+
import random
156+
random.seed(19680801)
157+
158+
The seed is John Hunter's birthday.
142159

143160
Writing an image comparison test
144161
--------------------------------

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.