Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 30cd364

Browse files
committed
Force GC run in tests that want clean up.
Some of these worked (by fluke?) in CPython, but didn't work in PyPy. The NumPy function ensures GC is run enough times on PyPy to be really cleared.
1 parent f809ee5 commit 30cd364

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

lib/matplotlib/tests/test_animation.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import gc
21
import os
32
from pathlib import Path
43
import subprocess
@@ -90,7 +89,7 @@ def test_animation_delete(anim):
9089
anim = animation.FuncAnimation(**anim)
9190
with pytest.warns(Warning, match='Animation was deleted'):
9291
del anim
93-
gc.collect()
92+
np.testing.break_cycles()
9493

9594

9695
def test_movie_writer_dpi_default():
@@ -214,7 +213,8 @@ def test_animation_repr_html(writer, html, want, anim):
214213
if want is None:
215214
assert html is None
216215
with pytest.warns(UserWarning):
217-
del anim # Animtion was never run, so will warn on cleanup.
216+
del anim # Animation was never run, so will warn on cleanup.
217+
np.testing.break_cycles()
218218
else:
219219
assert want in html
220220

@@ -324,6 +324,7 @@ def frames_generator():
324324
writer = NullMovieWriter()
325325
anim.save('unused.null', writer=writer)
326326
assert len(frames_generated) == 5
327+
np.testing.break_cycles()
327328
for f in frames_generated:
328329
# If cache_frame_data is True, then the weakref should be alive;
329330
# if cache_frame_data is False, then the weakref should be dead (None).

lib/matplotlib/tests/test_cbook.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,13 @@ def count(self):
198198
return count1
199199

200200
def is_empty(self):
201+
np.testing.break_cycles()
201202
assert self.callbacks._func_cid_map == {}
202203
assert self.callbacks.callbacks == {}
203204
assert self.callbacks._pickled_cids == set()
204205

205206
def is_not_empty(self):
207+
np.testing.break_cycles()
206208
assert self.callbacks._func_cid_map != {}
207209
assert self.callbacks.callbacks != {}
208210

lib/matplotlib/tests/test_style.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from contextlib import contextmanager
2-
import gc
32
from pathlib import Path
43
from tempfile import TemporaryDirectory
54
import sys
65

6+
import numpy as np
77
import pytest
88

99
import matplotlib as mpl
@@ -165,7 +165,7 @@ def test_xkcd_no_cm():
165165
assert mpl.rcParams["path.sketch"] is None
166166
plt.xkcd()
167167
assert mpl.rcParams["path.sketch"] == (1, 100, 2)
168-
gc.collect()
168+
np.testing.break_cycles()
169169
assert mpl.rcParams["path.sketch"] == (1, 100, 2)
170170

171171

0 commit comments

Comments
 (0)