pytest-mpl is a pytest plugin to facilitate image comparison for Matplotlib figures.
For each figure to test, an image is generated and then subtracted from an existing reference image. If the RMS of the residual is larger than a user-specified tolerance, the test will fail. Alternatively, the generated image can be hashed and compared to an expected value.
For more information, see the pytest-mpl documentation.
Installation
pip install pytest-mpl
For detailed instructions, see the installation guide in the pytest-mpl docs.
Usage
First, write test functions that create a figure. These image comparison tests are decorated with @pytest.mark.mpl_image_compare and return the figure for testing:
import matplotlib.pyplot as plt
import pytest
@pytest.mark.mpl_image_compare
def test_plot():
fig, ax = plt.subplots()
ax.plot([1, 2])
return fig
Then, generate reference images by running the test suite with the --mpl-generate-path option:
pytest --mpl-generate-path=baseline
Then, run the test suite as usual, but pass --mpl to compare the returned figures to the reference images:
pytest --mpl
By also passing --mpl-generate-summary=html, a summary of the image comparison results will be generated in HTML format:
For more information on how to configure and use pytest-mpl, see the pytest-mpl documentation.
Contributing
pytest-mpl is a community project maintained for and by its users. There are many ways you can help!
Report a bug or request a feature on GitHub
Improve the documentation or code
Release files for pytest-mpl 0.19.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytest_mpl-0.19.0.tar.gz | 881.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_mpl-0.19.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 910.0 kB
Release files / pytest_mpl-0.19.0.tar.gz
| Download URL | pytest_mpl-0.19.0.tar.gz |
|---|---|
| Size | 881.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c08e7b51ba4c98eed77ac3f3c6e336ed6163647d9e27ea1d928f79b542178cbe
|
|
BLAKE2b-256 checksum How to use checksums |
e8c1d5347e8aff4f6306f33caac80e1527831f733788ca98a6d58cfa0d40999c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / pytest_mpl-0.19.0-py3-none-any.whl
| Download URL | pytest_mpl-0.19.0-py3-none-any.whl |
|---|---|
| Size | 28.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ceb6f7201587b07af82ba8892631a29a4716fdc84306db3ec1b4ef3758f0507d
|
|
BLAKE2b-256 checksum How to use checksums |
a3f960a6c3da23525e600131eae9e17cad738e2e820335ab45e1ea78ec8df4cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|