Skip to main content

pytest plugin to help with testing figures output from Matplotlib - OGGM fork

Project description

pytest-mpl is a pytest plugin to facilitate image comparison for Matplotlib figures.

OGGM fork

pytest-mpl-oggm` is a shallow fork that adds a few OGGM specific features and enhancements.

Installation:

pip install pytest-mpl-oggm

To run the tests, pass --mpl-oggm to compare the returned figures to the reference images:

pytest --mpl-oggm

For more information about this fork, visit https://github.com/OGGM/pytest-mpl-oggm

Upstream pytest-mpl

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.

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.2.tar.gz (882.2 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.2-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pytest_mpl_oggm-0.180.2.tar.gz
Algorithm Hash digest
SHA256 f9a33d0d11d60c3f36457689120ec31ee5601bb51db7c9e8502c75bd09edd67a
MD5 bf411d71921545fe9682a721b00df7ad
BLAKE2b-256 587f3be9599a22d17db6087ba01449fdc4094947135ca43ea751f17167399100

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pytest_mpl_oggm-0.180.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f8901c9db4d6a3f4ad3433f325a6ca419835104d2f0968b9b62795390cb9dc89
MD5 4960683ad12e7738f953bf686de38270
BLAKE2b-256 d30781afe76e338260b0926f67561df2067128f08aa6221be6d60c7a9f965931

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