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.18.0.tar.gz (880.4 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.18.0-py3-none-any.whl (28.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_mpl-0.18.0.tar.gz
  • Upload date:
  • Size: 880.4 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.18.0.tar.gz
Algorithm Hash digest
SHA256 04c949ea1278a38ca3d8d675871f6c5a0958bfedfaf4fd8bfd4e25e5861759a7
MD5 60acd3bd23682cec56de97a9c6826bee
BLAKE2b-256 9c40ba3caed7a54a6a5fe035ecc62dbb473f6f41ecade2ea3e0474f7e8e65c5c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_mpl-0.18.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.18.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e474b7676957c521104dbe351df937da5e582231cd34daeb43b9d1ecc048e5c0
MD5 d1d67794d6d500515b490a4a915a0943
BLAKE2b-256 eb01f9128b75808840fc070042c57168c800da57d2d80b97071dc6f07c793d58

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