Skip to content

Commit 4f448e3

Browse files
committed
Write a new README.rst
1 parent 9edc946 commit 4f448e3

File tree

1 file changed

+66
-8
lines changed

1 file changed

+66
-8
lines changed

README.rst

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,66 @@
1-
This is a plugin to facilitate image comparison for
2-
`Matplotlib <http://www.matplotlib.org>`__ figures in pytest.
3-
4-
For each figure to test, the reference image is subtracted from the
5-
generated image, and the RMS of the residual is compared to a
6-
user-specified tolerance. If the residual is too large, the test will
7-
fail (this is implemented using helper functions from
8-
``matplotlib.testing``).
1+
``pytest-mpl``
2+
==============
3+
4+
``pytest-mpl`` is a `pytest <https://docs.pytest.org>`__ plugin to facilitate image comparison for `Matplotlib <http://www.matplotlib.org>`__ figures.
5+
6+
For each figure to test, an image is generated and then subtracted from an existing reference image.
7+
If the RMS of the residual is larger than a user-specified tolerance, the test will fail.
8+
Alternatively, the generated image can be hashed and compared to an expected value.
9+
10+
For more information, see the `pytest-mpl documentation <https://pytest-mpl.readthedocs.io>`__.
11+
12+
Installation
13+
------------
14+
.. code-block:: bash
15+
16+
pip install pytest-mpl
17+
18+
For detailed instructions, see the `installation guide <https://pytest-mpl.readthedocs.io/en/latest/installing.html>`__ in the ``pytest-mpl`` docs.
19+
20+
Usage
21+
-----
22+
First, write test functions that create a figure.
23+
These image comparison tests are decorated with ``@pytest.mark.mpl_image_compare`` and return the figure for testing:
24+
25+
.. code-block:: python
26+
27+
import matplotlib.pyplot as plt
28+
import pytest
29+
30+
@pytest.mark.mpl_image_compare
31+
def test_plot():
32+
fig, ax = plt.subplots()
33+
ax.plot([1, 2])
34+
return fig
35+
36+
Then, generate reference images by running the test suite with the ``--mpl-generate-path`` option:
37+
38+
.. code-block:: bash
39+
40+
pytest --mpl-generate-path=baseline
41+
42+
Then, run the test suite as usual, but pass ``--mpl`` to compare the returned figures to the reference images:
43+
44+
.. code-block:: bash
45+
46+
pytest --mpl
47+
48+
By also passing ``--mpl-generate-summary=html``, a summary of the image comparison results will be generated in HTML format:
49+
50+
+---------------+---------------+---------------+
51+
| |html all| | |html filter| | |html result| |
52+
+---------------+---------------+---------------+
53+
54+
For more information on how to configure and use ``pytest-mpl``, see the `pytest-mpl documentation <https://pytest-mpl.readthedocs.io>`__.
55+
56+
Contributing
57+
------------
58+
``pytest-mpl`` is a community project maintained for and by its users.
59+
There are many ways you can help!
60+
61+
- Report a bug or request a feature `on GitHub <https://github.com/matplotlib/pytest-mpl/issues>`__
62+
- Improve the documentation or code
63+
64+
.. |html all| image:: docs/images/html_all.png
65+
.. |html filter| image:: docs/images/html_filter.png
66+
.. |html result| image:: docs/images/html_result.png

0 commit comments

Comments
 (0)