@@ -6,9 +6,9 @@ Developer's tips for testing
6
6
7
7
Matplotlib has a testing infrastructure based onpytest _, making it easy to
8
8
write new tests. The tests are in:mod: `matplotlib.tests `, and customizations
9
- to the pytest testing infrastructure are in:mod: `matplotlib.tests.conftest `
10
- and :mod: ` matplotlib.testing `. (There is other old testing cruft around, please
11
- ignore it while we consolidate our testing to these locations.)
9
+ to the pytest testing infrastructure are in:mod: `matplotlib.testing `. (There
10
+ is other old testing cruft around, please ignore it while we consolidate our
11
+ testing to these locations.)
12
12
13
13
.. _pytest :http://doc.pytest.org/en/latest/
14
14
.. _mock :https://docs.python.org/dev/library/unittest.mock.html>
@@ -69,11 +69,11 @@ commands, such as:
69
69
70
70
======================== ===========
71
71
``--pep8 `` Perform pep8 checks (requirespytest-pep8 _)
72
- ``--no- network `` Disable tests that require network access
72
+ ``-m "not network" `` Disable tests that require network access
73
73
======================== ===========
74
74
75
75
Additional arguments are passed on to pytest. See the pytest documentation for
76
- supported arguments. Some of the more important ones are given here:
76
+ ` supported arguments `_ . Some of the more important ones are given here:
77
77
78
78
============================= ===========
79
79
``--verbose `` Be more verbose
@@ -84,26 +84,26 @@ supported arguments. Some of the more important ones are given here:
84
84
``--capture=no `` or ``-s `` Do not capture stdout
85
85
============================= ===========
86
86
87
- To run a single test from the command line, you can provide adot-separated
88
- path to the module, optionally followed by the function separated by two
89
- colons, e.g., (this is assuming the test is installed )::
87
+ To run a single test from the command line, you can provide afile path,
88
+ optionally followed by the function separated by two colons, e.g., (tests do
89
+ not need to be installed, but Matplotlib should be )::
90
90
91
- python tests.py matplotlib. tests. test_simplification::test_clipping
91
+ py.test lib/ matplotlib/ tests/ test_simplification.py ::test_clipping
92
92
93
- or by passing a file path, optionally followed by thefunction separated by two
94
- colons, e.g., (tests do not need to be installed, but Matplotlib should be) ::
93
+ or, if tests are installed, a dot-separated path to themodule, optionally
94
+ followed by the function separated by two colons, such as ::
95
95
96
- python tests.py lib/ matplotlib/ tests/test_simplification.py ::test_clipping
96
+ py.test --pyargs matplotlib. tests.test_simplification ::test_clipping
97
97
98
98
If you want to run the full test suite, but want to save wall time try
99
99
running the tests in parallel::
100
100
101
- python tests.py --capture=no --verbose -n 5
101
+ py.test --verbose -n 5
102
102
103
103
Depending on your version of Python and pytest-xdist, you may need to set
104
104
``PYTHONHASHSEED `` to a fixed value when running in parallel::
105
105
106
- PYTHONHASHSEED=0python tests.py --capture=no --verbose -n 5
106
+ PYTHONHASHSEED=0py.test --verbose -n 5
107
107
108
108
An alternative implementation that does not look at command line arguments
109
109
and works from within Python is to run the tests from the Matplotlib library
@@ -112,16 +112,10 @@ function :func:`matplotlib.test`::
112
112
import matplotlib
113
113
matplotlib.test()
114
114
115
- ..hint ::
116
-
117
- To run the tests you need to install pytest and mock if using python 2.7::
118
-
119
- pip install pytest
120
- pip install mock
121
-
122
115
123
116
.. _pytest-xdist :https://pypi.python.org/pypi/pytest-xdist
124
117
.. _pytest-timeout :https://pypi.python.org/pypi/pytest-timeout
118
+ .. _supported arguments :http://doc.pytest.org/en/latest/usage.html
125
119
126
120
127
121
Writing a simple test
@@ -143,7 +137,7 @@ begin with ``"test_"`` and then within those files for functions beginning with
143
137
Tests that have side effects that need to be cleaned up, such as created
144
138
figures using the pyplot interface or modified rc params, will be automatically
145
139
reset by the pytest fixture
146
- :func: `~matplotlib.tests .conftest.mpl_test_settings `.
140
+ :func: `~matplotlib.testing .conftest.mpl_test_settings `.
147
141
148
142
149
143
Writing an image comparison test