1- import gc
21import os
32from pathlib import Path
3+ import platform
44import subprocess
55import sys
66import weakref
@@ -87,10 +87,15 @@ def test_null_movie_writer(anim):
8787
8888@pytest .mark .parametrize ('anim' , [dict (klass = dict )], indirect = ['anim' ])
8989def test_animation_delete (anim ):
90+ if platform .python_implementation () == 'PyPy' :
91+ # Something in the test setup fixture lingers around into the test and
92+ # breaks pytest.warns on PyPy. This garbage collection fixes it.
93+ # https://foss.heptapod.net/pypy/pypy/-/issues/3536
94+ np .testing .break_cycles ()
9095 anim = animation .FuncAnimation (** anim )
9196 with pytest .warns (Warning , match = 'Animation was deleted' ):
9297 del anim
93- gc . collect ()
98+ np . testing . break_cycles ()
9499
95100
96101def test_movie_writer_dpi_default ():
@@ -201,6 +206,11 @@ def test_save_animation_smoketest(tmpdir, writer, frame_format, output, anim):
201206])
202207@pytest .mark .parametrize ('anim' , [dict (klass = dict )], indirect = ['anim' ])
203208def test_animation_repr_html (writer , html , want , anim ):
209+ if platform .python_implementation () == 'PyPy' :
210+ # Something in the test setup fixture lingers around into the test and
211+ # breaks pytest.warns on PyPy. This garbage collection fixes it.
212+ # https://foss.heptapod.net/pypy/pypy/-/issues/3536
213+ np .testing .break_cycles ()
204214 if (writer == 'imagemagick' and html == 'html5'
205215 # ImageMagick delegates to ffmpeg for this format.
206216 and not animation .FFMpegWriter .isAvailable ()):
@@ -214,7 +224,8 @@ def test_animation_repr_html(writer, html, want, anim):
214224 if want is None :
215225 assert html is None
216226 with pytest .warns (UserWarning ):
217- del anim # Animtion was never run, so will warn on cleanup.
227+ del anim # Animation was never run, so will warn on cleanup.
228+ np .testing .break_cycles ()
218229 else :
219230 assert want in html
220231
@@ -324,6 +335,7 @@ def frames_generator():
324335 writer = NullMovieWriter ()
325336 anim .save ('unused.null' , writer = writer )
326337 assert len (frames_generated ) == 5
338+ np .testing .break_cycles ()
327339 for f in frames_generated :
328340 # If cache_frame_data is True, then the weakref should be alive;
329341 # if cache_frame_data is False, then the weakref should be dead (None).
0 commit comments