@@ -112,7 +112,7 @@ def isAvailable(self):
112112# matplotlib.testing.image_comparison
113113@cleanup
114114@pytest .mark .parametrize ('writer, extension' , WRITER_OUTPUT )
115- def test_save_animation_smoketest (writer , extension ):
115+ def test_save_animation_smoketest (tmpdir , writer , extension ):
116116 try :
117117 # for ImageMagick the rcparams must be patched to account for
118118 # 'convert' being a built in MS tool, not the imagemagick
@@ -138,20 +138,15 @@ def animate(i):
138138 line .set_data (x , y )
139139 return line ,
140140
141- # Use NamedTemporaryFile: will be automatically deleted
142- F = tempfile .NamedTemporaryFile (suffix = '.' + extension )
143- F .close ()
144- anim = animation .FuncAnimation (fig , animate , init_func = init , frames = 5 )
145- try :
146- anim .save (F .name , fps = 30 , writer = writer , bitrate = 500 )
147- except UnicodeDecodeError :
148- xfail ("There can be errors in the numpy import stack, "
149- "see issues #1891 and #2679" )
150- finally :
141+ # Use temporary directory for the file-based writers, which produce a file
142+ # per frame with known names.
143+ with tmpdir .as_cwd ():
144+ anim = animation .FuncAnimation (fig , animate , init_func = init , frames = 5 )
151145 try :
152- os .remove (F .name )
153- except Exception :
154- pass
146+ anim .save ('movie.' + extension , fps = 30 , writer = writer , bitrate = 500 )
147+ except UnicodeDecodeError :
148+ xfail ("There can be errors in the numpy import stack, "
149+ "see issues #1891 and #2679" )
155150
156151
157152@cleanup
0 commit comments