@@ -90,7 +90,6 @@ When generating a hash library, the tests will also be run as usual against the
90
90
existing hash library specified by ``--mpl-hash-library `` or the keyword argument.
91
91
However, generating baseline images will always result in the tests being skipped.
92
92
93
-
94
93
Hybrid Mode: Hashes and Images
95
94
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
96
95
@@ -278,6 +277,62 @@ decorator:
278
277
This will make the test insensitive to changes in e.g. the freetype
279
278
library.
280
279
280
+ Supported formats and deterministic output
281
+ ------------------------------------------
282
+
283
+ By default, pytest-mpl will save and compare figures in PNG format. However,
284
+ it is possible to set the format to use by setting e.g. ``savefig_kwargs={'format': 'pdf'} ``
285
+ in ``mpl_image_compare ``. Supported formats are ``'eps' ``, ``'pdf' ``, ``'png' ``, and ``'svg' ``.
286
+ Note that Ghostscript is required to be installed for comparing PDF and EPS figures, while
287
+ Inkscape is required for SVG comparison.
288
+
289
+ By default, Matplotlib does not produce deterministic output that will
290
+ have a consistent hash every time it is run, or over different Matplotlib versions.
291
+ In order to enforce that the output is deterministic, you will need to do the following:
292
+
293
+ PNG
294
+ ^^^
295
+
296
+ For PNG files, the output can be made deterministic by setting::
297
+
298
+ @pytest.mark.mpl_image_compare(savefig_kwargs={'metadata': {"Software": None}})
299
+
300
+ PDF
301
+ ^^^
302
+
303
+ For PDF files, the output can be made deterministic by setting::
304
+
305
+ @pytest.mark.mpl_image_compare(savefig_kwargs={'format': 'pdf',
306
+ 'metadata': {"Creator": None,
307
+ "Producer": None,
308
+ "CreationDate": None}})
309
+
310
+ EPS
311
+ ^^^
312
+
313
+ For PDF files, the output can be made deterministic by setting::
314
+
315
+ @pytest.mark.mpl_image_compare(savefig_kwargs={'format': 'pdf',
316
+ 'metadata': {"Creator": "test"})
317
+
318
+ and in addition you will need to set the SOURCE_DATE_EPOCH environment variable to
319
+ a constant value (this is a unit timestamp)::
320
+
321
+ os.environ['SOURCE_DATE_EPOCH'] = '1680254601'
322
+
323
+ You could do this inside the test.
324
+
325
+ SVG
326
+ ^^^
327
+
328
+ For SVG files, the output can be made deterministic by setting::
329
+
330
+ @pytest.mark.mpl_image_compare(savefig_kwargs={'metadata': '{"Date": None}})
331
+
332
+ and in addition, you should make sure the following rcParam is set to a constant string::
333
+
334
+ plt.rcParams['svg.hashsalt'] = 'test'
335
+
281
336
Test failure example
282
337
--------------------
283
338
0 commit comments