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

Skip to content

Commit 27d1949

Browse files
committed
Better error reporting on failure of cache_frame_data test.
This avoids an obscure pytest assertion failure ``` > assert weakref_assertion_fn(f()) E assert False E + where False = <function <lambda> at 0x7f49d8bfdb80>(None) E + where None = <weakref at 0x7f49d76c3360; dead>() ``` if refactoring animation and causing the test to fail. One now gets ``` # If cache_frame_data is True, then the weakref should be alive; # if cache_frame_data is False, then the weakref should be dead (None). > assert (f() is None) != cache_frame_data E assert (None is None) != True E + where None = <weakref at 0x7f4a3416c7c0; dead>() ```
1 parent b459bc7 commit 27d1949

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

lib/matplotlib/tests/test_animation.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,8 @@ def test_failing_ffmpeg(tmpdir, monkeypatch):
237237
make_animation().save("test.mpeg")
238238

239239

240-
@pytest.mark.parametrize("cache_frame_data, weakref_assertion_fn", [
241-
pytest.param(
242-
False, lambda ref: ref is None, id='cache_frame_data_is_disabled'),
243-
pytest.param(
244-
True, lambda ref: ref is not None, id='cache_frame_data_is_enabled'),
245-
])
246-
def test_funcanimation_holding_frames(cache_frame_data, weakref_assertion_fn):
240+
@pytest.mark.parametrize("cache_frame_data", [False, True])
241+
def test_funcanimation_cache_frame_data(cache_frame_data):
247242
fig, ax = plt.subplots()
248243
line, = ax.plot([], [])
249244

@@ -282,4 +277,6 @@ def frames_generator():
282277
anim.save('unused.null', writer=writer)
283278
assert len(frames_generated) == 5
284279
for f in frames_generated:
285-
assert weakref_assertion_fn(f())
280+
# If cache_frame_data is True, then the weakref should be alive;
281+
# if cache_frame_data is False, then the weakref should be dead (None).
282+
assert (f() is None) != cache_frame_data

0 commit comments

Comments
 (0)