mercredi 26 septembre 2018

PyTest Matplotlib Figure Appears on Show

I have a complicated method called plotter() which processes some data and produces a matplotlib plot with several components. Due to its complexity I simply want to test that the plot appears. This will confirm that all of the data is processed reasonably and that something gets shown without any errors being thrown. I am not looking to run an image comparison as that's not currently possible for this project.

My function is too complicated to show here, so the following example could be considered instead.

import matplotlib.pyplot as plt
import numpy as np

def plotter():
    x = np.arange(0,10)
    y = 2*x
    fig = plt.plot(x, y)
    plt.show()

Is there a way to use PyTest to simply assert that a figure appears? If not then solutions using other test frameworks would also be greatly appreciated.

(For context I am using Python 3.)

Aucun commentaire:

Enregistrer un commentaire