6
6
This is a plugin to facilitate image comparison for
7
7
`Matplotlib <http://www.matplotlib.org >`__ figures in pytest.
8
8
9
- Matplotlib includes a number of test utilities and decorators, but these
10
- are geared towards the `nose <http://nose.readthedocs.org/ >`__ testing
11
- framework. Pytest-mpl makes it easy to compare figures produced by tests
12
- to reference images when using `pytest <http://pytest.org >`__.
13
-
14
9
For each figure to test, the reference image is subtracted from the
15
10
generated image, and the RMS of the residual is compared to a
16
11
user-specified tolerance. If the residual is too large, the test will
@@ -23,23 +18,17 @@ section below.
23
18
Installing
24
19
----------
25
20
26
- This plugin is compatible with Python 2.6, 2.7, and 3.3 and later, and
27
- requires `pytest <http://pytest.org >`__,
28
- `matplotlib <http://www.matplotlib.org >`__ and
29
- `nose <http://nose.readthedocs.org/ >`__ to be installed (nose is
30
- required by Matplotlib).
31
-
32
- To install, you can do:
21
+ This plugin is compatible with Python 2.7, and 3.5 and later, and
22
+ requires `pytest <http://pytest.org >`__ and
23
+ `matplotlib <http://www.matplotlib.org> ` to be installed.
33
24
34
- ::
25
+ To install, you can do ::
35
26
36
27
pip install pytest-mpl
37
28
38
- You can check that the plugin is registered with pytest by doing:
39
-
40
- ::
29
+ You can check that the plugin is registered with pytest by doing::
41
30
42
- py.test --version
31
+ pytest --version
43
32
44
33
which will show a list of plugins:
45
34
@@ -71,24 +60,20 @@ function returns a Matplotlib figure (or any figure object that has a
71
60
72
61
To generate the baseline images, run the tests with the
73
62
``--mpl-generate-path `` option with the name of the directory where the
74
- generated images should be placed:
75
-
76
- ::
63
+ generated images should be placed::
77
64
78
- py.test --mpl-generate-path=baseline
65
+ pytest --mpl-generate-path=baseline
79
66
80
67
If the directory does not exist, it will be created. The directory will
81
- be interpreted as being relative to where you are running ``py.test ``.
68
+ be interpreted as being relative to where you are running ``pytest ``.
82
69
Once you are happy with the generated images, you should move them to a
83
70
sub-directory called ``baseline `` relative to the test files (this name
84
71
is configurable, see below). You can also generate the baseline images
85
72
directly in the right directory.
86
73
87
- You can then run the tests simply with:
74
+ You can then run the tests simply with::
88
75
89
- ::
90
-
91
- py.test --mpl
76
+ pytest --mpl
92
77
93
78
and the tests will pass if the images are the same. If you omit the
94
79
``--mpl `` option, the tests will run but will only check that the code
@@ -145,11 +130,9 @@ a comma-separated list of URLs (real commas in the URL should be encoded
145
130
as ``%2C ``).
146
131
147
132
Finally, you can also set a custom baseline directory globally when
148
- running tests by running ``py.test `` with:
149
-
150
- ::
133
+ running tests by running ``pytest `` with::
151
134
152
- py.test --mpl --mpl-baseline-path=baseline_images
135
+ pytest --mpl --mpl-baseline-path=baseline_images
153
136
154
137
This directory will be interpreted as being relative to where the tests
155
138
are run. In addition, if both this option and the ``baseline_dir ``
@@ -190,9 +173,7 @@ Test failure example
190
173
191
174
If the images produced by the tests are correct, then the test will
192
175
pass, but if they are not, the test will fail with a message similar to
193
- the following:
194
-
195
- ::
176
+ the following::
196
177
197
178
E Exception: Error: Image files did not match.
198
179
E RMS Value: 142.2287807767823
@@ -226,7 +207,7 @@ By default, the expected, actual and difference files are written to a
226
207
temporary directory with a non-deterministic path. If you want to instead
227
208
write them to a specific directory, you can use::
228
209
229
- py.test --mpl --mpl-results-path=results
210
+ pytest --mpl --mpl-results-path=results
230
211
231
212
The ``results `` directory will then contain one sub-directory per test, and each
232
213
sub-directory will contain the three files mentioned above. If you are using a
@@ -242,12 +223,10 @@ Running the tests for pytest-mpl
242
223
--------------------------------
243
224
244
225
If you are contributing some changes and want to run the tests, first
245
- install the latest version of the plugin then do:
246
-
247
- ::
226
+ install the latest version of the plugin then do::
248
227
249
228
cd tests
250
- py.test --mpl
229
+ pytest --mpl
251
230
252
231
The reason for having to install the plugin first is to ensure that the
253
232
plugin is correctly loaded as part of the test suite.
0 commit comments