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.17.0.tar.gz (885.6 kB view details)

Uploaded Source

Built Distribution

pytest_mpl-0.17.0-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file pytest-mpl-0.17.0.tar.gz.

File metadata

  • Download URL: pytest-mpl-0.17.0.tar.gz
  • Upload date:
  • Size: 885.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for pytest-mpl-0.17.0.tar.gz
Algorithm Hash digest
SHA256 fbef05d7e664b4b33452fb698ac188e522791f327de34e7ea37dbdfe9d52cac6
MD5 5c021e0c9715eb2e8dc73739ec734ee8
BLAKE2b-256 a981636f9ea4ec0182abc0ab96e5abeab39fc1d9ce8fecf19e2943d685de519f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_mpl-0.17.0-py3-none-any.whl
  • Upload date:
  • Size: 27.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for pytest_mpl-0.17.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ee7cf902ef071e45ae14fe190b3d8a9839c2fd8933e0514bf58df310d8ed66b
MD5 471a568d98da0fc59b8e65ee810b35c0
BLAKE2b-256 f3323b5d6973cc8bdc320736ee608377e2756b1042ed162ca2d2ee5555f2d117

See more details on using hashes here.

Supported by

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