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

Skip to content

Commit 54d3856

Browse files
authored
TST: Skip tests that use a large amount of memory by default (#31007)
* TST: Reduce memory usage of test_downsample_interpolation_stage By cutting the grid by one-tenth in each dimension, this cuts memory usage from 1.0GiB to 65.2MiB. I temporarily added an assert in `_ImageBase._make_image` to confirm that the interpolation stage did correctly switch to 'rgba' as well. * TST: Delete test_invisible_Line_rendering This test tries to check for slowdowns, which is inherently flaky (as noted by the comment), and we don't check `set_visible` for other artists. * TST: Skip tests that use a large amount of memory by default According to memray, these tests use fairly large amounts of memory: - lib/matplotlib/tests/test_simplification.py::test_throw_rendering_complexity_exceeded: 2.2GiB - lib/matplotlib/tests/test_agg.py::test_chunksize_fails: 2.0GiB - lib/matplotlib/tests/test_image.py::test_large_image[png-col-16777216-2\\*\\*24 rows-upper]: 1.0GiB - lib/matplotlib/tests/test_image.py::test_large_image[png-col-16777216-2\\*\\*24 rows-lower]: 1.0GiB - lib/matplotlib/tests/test_image.py::test_large_image[png-row-8388608-2\\*\\*23 columns-lower]: 537.8MiB - lib/matplotlib/tests/test_image.py::test_large_image[png-row-8388608-2\\*\\*23 columns-upper]: 537.8MiB The next closest tests use just 216MiB, then 145.5MiB, etc. and then the majority under 100MiB. If you're unlucky, with 4-way xdist you might use upwards of 6GiB RAM if you get all these on separate processes. The above tests are all fairly low-level checks for Agg renderer limits that are not likely to change often, so skip them by default unless on CI.
1 parent ad15a4c commit 54d3856

11 files changed

Lines changed: 31 additions & 59 deletions

File tree

doc/devel/testing.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ In the root directory of your development repository run::
5252
``--capture=no`` or ``-s`` Do not capture stdout
5353
============================= ===========
5454

55+
Some tests may use a large amount of memory (>0.5GiB); to enable those tests, set the
56+
environment variable ``MPL_TEST_EXPENSIVE``.
57+
5558
To run a single test from the command line, you can provide a file path, optionally
5659
followed by the function separated by two colons, e.g., (tests do not need to be
5760
installed, but Matplotlib should be)::

lib/matplotlib/testing/conftest.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import pytest
1+
import os
22
import sys
3+
4+
import pytest
5+
36
import matplotlib
47
from matplotlib import _api
58

@@ -80,6 +83,13 @@ def mpl_test_settings(request):
8083
matplotlib.use(prev_backend)
8184

8285

86+
@pytest.fixture
87+
def high_memory(pytestconfig):
88+
from matplotlib.testing import is_ci_environment
89+
if not (os.environ.get('MPL_TEST_EXPENSIVE') or is_ci_environment()):
90+
pytest.skip('Test uses too much memory')
91+
92+
8393
@pytest.fixture
8494
def pd():
8595
"""

lib/matplotlib/testing/conftest.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ def pytest_unconfigure(config: pytest.Config) -> None: ...
77
@pytest.fixture
88
def mpl_test_settings(request: pytest.FixtureRequest) -> None: ...
99
@pytest.fixture
10+
def high_memory(pytestconfig: pytest.Config) -> None: ...
11+
@pytest.fixture
1012
def pd() -> ModuleType: ...
1113
@pytest.fixture
1214
def xr() -> ModuleType: ...

lib/matplotlib/tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from matplotlib.testing.conftest import ( # noqa
2-
mpl_test_settings, pytest_configure, pytest_unconfigure, pd, text_placeholders, xr)
2+
pytest_configure, pytest_unconfigure,
3+
high_memory, mpl_test_settings, pd, text_placeholders, xr)

lib/matplotlib/tests/test_agg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ def test_draw_path_collection_error_handling():
328328
fig.canvas.draw()
329329

330330

331-
def test_chunksize_fails():
331+
def test_chunksize_fails(high_memory):
332332
# NOTE: This test covers multiple independent test scenarios in a single
333333
# function, because each scenario uses ~2GB of memory and we don't
334334
# want parallel test executors to accidentally run multiple of these

lib/matplotlib/tests/test_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ def test_downsample_interpolation_stage(fig_test, fig_ref):
15551555
# Fixing random state for reproducibility
15561556
np.random.seed(19680801)
15571557

1558-
grid = np.random.rand(4000, 4000)
1558+
grid = np.random.rand(400, 400)
15591559
ax = fig_ref.subplots()
15601560
ax.imshow(grid, interpolation='auto', cmap='viridis',
15611561
interpolation_stage='rgba')
@@ -1583,7 +1583,7 @@ def test_rc_interpolation_stage():
15831583
'dim, size, msg', [['row', 2**23, r'2\*\*23 columns'],
15841584
['col', 2**24, r'2\*\*24 rows']])
15851585
@check_figures_equal()
1586-
def test_large_image(fig_test, fig_ref, dim, size, msg, origin):
1586+
def test_large_image(fig_test, fig_ref, dim, size, msg, origin, high_memory):
15871587
# Check that Matplotlib downsamples images that are too big for AGG
15881588
# See issue #19276. Currently the fix only works for png output but not
15891589
# pdf or svg output.

lib/matplotlib/tests/test_lines.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import itertools
66
import platform
7-
import timeit
87
from types import SimpleNamespace
98

109
from cycler import cycler
@@ -31,52 +30,6 @@ def test_segment_hits():
3130
assert_array_equal(mlines.segment_hits(cx, cy, x, y, radius), [0])
3231

3332

34-
# Runtimes on a loaded system are inherently flaky. Not so much that a rerun
35-
# won't help, hopefully.
36-
@pytest.mark.flaky(reruns=5)
37-
def test_invisible_Line_rendering():
38-
"""
39-
GitHub issue #1256 identified a bug in Line.draw method
40-
41-
Despite visibility attribute set to False, the draw method was not
42-
returning early enough and some pre-rendering code was executed
43-
though not necessary.
44-
45-
Consequence was an excessive draw time for invisible Line instances
46-
holding a large number of points (Npts> 10**6)
47-
"""
48-
# Creates big x and y data:
49-
N = 10**7
50-
x = np.linspace(0, 1, N)
51-
y = np.random.normal(size=N)
52-
53-
# Create a plot figure:
54-
fig = plt.figure()
55-
ax = plt.subplot()
56-
57-
# Create a "big" Line instance:
58-
l = mlines.Line2D(x, y)
59-
l.set_visible(False)
60-
# but don't add it to the Axis instance `ax`
61-
62-
# [here Interactive panning and zooming is pretty responsive]
63-
# Time the canvas drawing:
64-
t_no_line = min(timeit.repeat(fig.canvas.draw, number=1, repeat=3))
65-
# (gives about 25 ms)
66-
67-
# Add the big invisible Line:
68-
ax.add_line(l)
69-
70-
# [Now interactive panning and zooming is very slow]
71-
# Time the canvas drawing:
72-
t_invisible_line = min(timeit.repeat(fig.canvas.draw, number=1, repeat=3))
73-
# gives about 290 ms for N = 10**7 pts
74-
75-
slowdown_factor = t_invisible_line / t_no_line
76-
slowdown_threshold = 2 # trying to avoid false positive failures
77-
assert slowdown_factor < slowdown_threshold
78-
79-
8033
def test_set_line_coll_dash():
8134
fig, ax = plt.subplots()
8235
np.random.seed(0)

lib/matplotlib/tests/test_simplification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ def test_start_with_moveto():
455455
assert segs[0][1] == Path.MOVETO
456456

457457

458-
def test_throw_rendering_complexity_exceeded():
458+
def test_throw_rendering_complexity_exceeded(high_memory):
459459
plt.rcParams['path.simplify'] = False
460460
xx = np.arange(2_000_000)
461461
yy = np.random.rand(2_000_000)
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
from matplotlib.testing.conftest import (mpl_test_settings, # noqa
2-
pytest_configure, pytest_unconfigure)
1+
from matplotlib.testing.conftest import ( # noqa
2+
pytest_configure, pytest_unconfigure,
3+
high_memory, mpl_test_settings)
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
from matplotlib.testing.conftest import (mpl_test_settings, # noqa
2-
pytest_configure, pytest_unconfigure)
1+
from matplotlib.testing.conftest import ( # noqa
2+
pytest_configure, pytest_unconfigure,
3+
high_memory, mpl_test_settings)

0 commit comments

Comments
 (0)