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.

This fork adds a few OGGM specific features and enhancements.

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_oggm-0.180.1.tar.gz (882.0 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_oggm-0.180.1-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

Details for the file pytest_mpl_oggm-0.180.1.tar.gz.

File metadata

  • Download URL: pytest_mpl_oggm-0.180.1.tar.gz
  • Upload date:
  • Size: 882.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for pytest_mpl_oggm-0.180.1.tar.gz
Algorithm Hash digest
SHA256 1c66958f10f67bce514eab8de484576b650bee403cf77a9d0f8755aa31f0c897
MD5 f21dd47599d66651af4045a3b7426470
BLAKE2b-256 3ded0c2270aa0f1d10dc4e3aa68d2430a7b702046b82301a8d9a859eb420ff7f

See more details on using hashes here.

File details

Details for the file pytest_mpl_oggm-0.180.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_mpl_oggm-0.180.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5d5b3c0987301be835fee8dee1098a2d11d5edade106b7f5b4890536541df92b
MD5 5f122605b9b49ecf1580a24e36c01bd4
BLAKE2b-256 4865c949c920518762b08b656c3f93f6adb18554e7db08ae9c2a0a2d4d20d74c

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