lundi 7 septembre 2015

how to close a pyplot windows in python unit test?

During a test of a python script I generated also some plots. They appear (one by one) in separate esternal windows.

To continue the test I have to manualy close these windows.

Is there any possibility to automaticaly close the plot windows generate by unit test?

I used plt.close('all'), but it seems not to work.

# -*- coding: utf-8 -*-  
""" controllo elabora"""  
import unittest   
import os  
import numpy as np  
import matplotlib.pyplot as plt  
import disegno_caotico as DC   

d1 = DC.disegno_caotico()  

class LearningCase(unittest.TestCase):  

    def setUp(self):  
        plt.close('all') # closes all the figure windows  

    def tearDown(self):      
        plt.close('all') # closes all the figure windows  

    def test_disegno_0(self):  
        """ Riassumo i valori delle risposte raggrupate per i pazienti di cui ho i dati  
            Non ho nessun assert, perché essenzialmente voglio vedere se  
                per un umano, si leggono bene i dati """  
        N = 5  
        x = range(N)  
        y = range(N)  
        fig = d1.disegna_risultati(x,y)  
        plt.close('all')   # non funziona, non chiude in automatico il disegno 

I sow the discussion Closing pyplot windows but my case is different.

Thanks.

Andrea

Aucun commentaire:

Enregistrer un commentaire