Skip to content

ENH Use pytest-mpl for testing image generation #532

@drewejohnson

Description

@drewejohnson

Is your feature request related to a problem? Please describe.
Testing our images is good! There's a lot of internal code to wrap some matplotlib functionality for image checking.

def compare_or_update_plot(f):
"""Build a decorator that wraps a plot test
The test function must produce a single figure that will be
compared to the expected figure during the test. If the --update
command line option is given, then the newly generated figure
will be save in place of the expected figure
"""
update = config["update"]
baseline = (FIG_RESULT_BASE / f.__name__).with_suffix(".png")
testFile = baseline.with_name("{}-test.png".format(f.__name__))
# TODO Don't convert to str - needed because MPL for python 3.5
# doesn't support saving as pathlib.Path instances
baseline = str(baseline)
testFile = str(testFile)
@wraps(f)
def wrapped(*args, **kwargs):
f(*args, **kwargs)
fig = pyplot.gcf()
if update:
fig.savefig(baseline)
return
fig.savefig(testFile)
res = compare_images(baseline, testFile, tol=config["plot_tolerance"])
assert res is None, res
remove(testFile)
# If a test is tagged with this decorator, mark is with the
# plot mark automatically
pytest.mark.plot(wrapped)
return wrapped

Describe the solution you'd like
What if we didn't do that? What if we used https://github.com/matplotlib/pytest-mpl instead?

Describe alternatives you've considered
We keep what we have? Doesn't seem super maintainable

Additional context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions