Skip to content

Commit 6a0c3ee

Browse files
committed
Update pytest documentation based on review.
* Prefer py.test over tests.py * Remove redundant hint * Add link to further pytest documentation * Tweak some sentence structure
1 parent a4427a1 commit 6a0c3ee

File tree

3 files changed

+35
-41
lines changed

3 files changed

+35
-41
lines changed

INSTALL

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,15 @@ or example code.
106106
If you want to try the many demos that come in the matplotlib source
107107
distribution, download the :file:`*.tar.gz` file and look in the
108108
:file:`examples` subdirectory.
109-
To run the test suite, copy the :file:`lib\\matplotlib\\tests` and
110-
:file:`lib\\mpl_toolkits\\tests` directories from the source
111-
distribution to :file:`sys.prefix\\Lib\\site-packages\\matplotlib` and
112-
:file:`sys.prefix\\Lib\\site-packages\\mpl_toolkits` respectively, and
113-
install `pytest <https://pypi.python.org/pypi/pytest>`_, `mock
114-
<https://pypi.python.org/pypi/mock>`_, Pillow, MiKTeX, GhostScript,
115-
ffmpeg, avconv, mencoder, ImageMagick, and `Inkscape
116-
<https://inkscape.org/>`_.
109+
To run the test suite:
110+
111+
* extract the :file:`lib\\matplotlib\\tests` or
112+
:file:`lib\\mpl_toolkits\\tests` directories from the source distribution;
113+
* install test dependencies: `pytest <https://pypi.python.org/pypi/pytest>`_,
114+
`mock <https://pypi.python.org/pypi/mock>`_, Pillow, MiKTeX, GhostScript,
115+
ffmpeg, avconv, mencoder, ImageMagick, and `Inkscape
116+
<https://inkscape.org/>`_;
117+
* run ``py.test path\\to\\tests\\directory``.
117118

118119

119120

README.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@ Testing
2020

2121
After installation, you can launch the test suite::
2222

23-
python tests.py
23+
py.test
2424

2525
Or from the Python interpreter::
2626

2727
import matplotlib
2828
matplotlib.test()
2929

3030
Consider reading http://matplotlib.org/devel/coding_guide.html#testing for
31-
more information. Note that the test suite requires pytest and on Python 2.7
32-
mock which are not installed by default. Please install with pip or your
33-
package manager of choice.
31+
more information. Note that the test suite requires pytest and, on Python 2.7,
32+
mock. Please install with pip or your package manager of choice.
3433

3534
Contact
3635
=======

doc/devel/testing.rst

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
Developer's tips for testing
55
============================
66

7-
Matplotlib has a testing infrastructure based on pytest_, making it easy to
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.)
7+
Matplotlib's testing infrastructure depends on pytest_. The tests are in
8+
:file:`lib/matplotlib/tests`, and customizations to the pytest testing
9+
infrastructure are in :mod:`matplotlib.testing`.
1210

1311
.. _pytest: http://doc.pytest.org/en/latest/
1412
.. _mock: https://docs.python.org/dev/library/unittest.mock.html>
1513
.. _Ghostscript: https://www.ghostscript.com/
1614
.. _Inkscape: https://inkscape.org
1715
.. _pytest-cov: https://pytest-cov.readthedocs.io/en/latest/
1816
.. _pytest-pep8: https://pypi.python.org/pypi/pytest-pep8
17+
.. _pytest-xdist: https://pypi.python.org/pypi/pytest-xdist
18+
.. _pytest-timeout: https://pypi.python.org/pypi/pytest-timeout
1919

2020
Requirements
2121
------------
@@ -31,6 +31,8 @@ Optionally you can install:
3131

3232
- pytest-cov_ to collect coverage information
3333
- pytest-pep8_ to test coding standards
34+
- pytest-timeout_ to limit runtime in case of stuck tests
35+
- pytest-xdist_ to run tests in parallel
3436

3537

3638
Building matplotlib for image comparison tests
@@ -69,11 +71,11 @@ commands, such as:
6971

7072
======================== ===========
7173
``--pep8`` Perform pep8 checks (requires pytest-pep8_)
72-
``--no-network`` Disable tests that require network access
74+
``-m "not network"`` Disable tests that require network access
7375
======================== ===========
7476

7577
Additional arguments are passed on to pytest. See the pytest documentation for
76-
supported arguments. Some of the more important ones are given here:
78+
`supported arguments`_. Some of the more important ones are given here:
7779

7880
============================= ===========
7981
``--verbose`` Be more verbose
@@ -84,26 +86,26 @@ supported arguments. Some of the more important ones are given here:
8486
``--capture=no`` or ``-s`` Do not capture stdout
8587
============================= ===========
8688

87-
To run a single test from the command line, you can provide a dot-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)::
89+
To run a single test from the command line, you can provide a file path,
90+
optionally followed by the function separated by two colons, e.g., (tests do
91+
not need to be installed, but Matplotlib should be)::
9092

91-
python tests.py matplotlib.tests.test_simplification::test_clipping
93+
py.test lib/matplotlib/tests/test_simplification.py::test_clipping
9294

93-
or by passing a file path, optionally followed by the function separated by two
94-
colons, e.g., (tests do not need to be installed, but Matplotlib should be)::
95+
or, if tests are installed, a dot-separated path to the module, optionally
96+
followed by the function separated by two colons, such as::
9597

96-
python tests.py lib/matplotlib/tests/test_simplification.py::test_clipping
98+
py.test --pyargs matplotlib.tests.test_simplification::test_clipping
9799

98100
If you want to run the full test suite, but want to save wall time try
99101
running the tests in parallel::
100102

101-
python tests.py --capture=no --verbose -n 5
103+
py.test --verbose -n 5
102104

103105
Depending on your version of Python and pytest-xdist, you may need to set
104106
``PYTHONHASHSEED`` to a fixed value when running in parallel::
105107

106-
PYTHONHASHSEED=0 python tests.py --capture=no --verbose -n 5
108+
PYTHONHASHSEED=0 py.test --verbose -n 5
107109

108110
An alternative implementation that does not look at command line arguments
109111
and works from within Python is to run the tests from the Matplotlib library
@@ -112,16 +114,8 @@ function :func:`matplotlib.test`::
112114
import matplotlib
113115
matplotlib.test()
114116

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
121117

122-
123-
.. _pytest-xdist: https://pypi.python.org/pypi/pytest-xdist
124-
.. _pytest-timeout: https://pypi.python.org/pypi/pytest-timeout
118+
.. _supported arguments: http://doc.pytest.org/en/latest/usage.html
125119

126120

127121
Writing a simple test
@@ -140,10 +134,10 @@ Pytest determines which functions are tests by searching for files whose names
140134
begin with ``"test_"`` and then within those files for functions beginning with
141135
``"test"`` or classes beginning with ``"Test"``.
142136

143-
Tests that have side effects that need to be cleaned up, such as created
144-
figures using the pyplot interface or modified rc params, will be automatically
145-
reset by the pytest fixture
146-
:func:`~matplotlib.tests.conftest.mpl_test_settings`.
137+
Some tests have internal side effects that need to be cleaned up after their
138+
execution (such as created figures or modified rc params). The pytest fixture
139+
:func:`~matplotlib.testing.conftest.mpl_test_settings` will automatically clean
140+
these up; there is no need to do anything further.
147141

148142

149143
Writing an image comparison test

0 commit comments

Comments
 (0)