Skip to main content

pytest plugin to help with testing figures output from Matplotlib

Project description

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:

html all

html filter

html result

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_mpl-0.19.0.tar.gz (881.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_mpl-0.19.0-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

File details

Details for the file pytest_mpl-0.19.0.tar.gz.

File metadata

  • Download URL: pytest_mpl-0.19.0.tar.gz
  • Upload date:
  • Size: 881.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_mpl-0.19.0.tar.gz
Algorithm Hash digest
SHA256 c08e7b51ba4c98eed77ac3f3c6e336ed6163647d9e27ea1d928f79b542178cbe
MD5 f0013d44ddfa7fffe6fe41ef30c06f7c
BLAKE2b-256 e8c1d5347e8aff4f6306f33caac80e1527831f733788ca98a6d58cfa0d40999c

See more details on using hashes here.

File details

Details for the file pytest_mpl-0.19.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_mpl-0.19.0-py3-none-any.whl
  • Upload date:
  • Size: 28.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pytest_mpl-0.19.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ceb6f7201587b07af82ba8892631a29a4716fdc84306db3ec1b4ef3758f0507d
MD5 5ab82ee20d9bba50d7512f7ec66340a9
BLAKE2b-256 a3f960a6c3da23525e600131eae9e17cad738e2e820335ab45e1ea78ec8df4cb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page