Skip to content

Commit 8b5ae9d

Browse files
committed
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_downsample_interpolation_stage[png]: 1.0GiB - lib/matplotlib/tests/test_lines.py::test_invisible_Line_rendering: 822.0MiB - 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 8615068 commit 8b5ae9d

File tree

10 files changed

+35
-12
lines changed

10 files changed

+35
-12
lines changed

doc/devel/testing.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ In the root directory of your development repository run::
5050
``-n NUM`` Run tests in parallel over NUM
5151
processes (requires pytest-xdist_)
5252
``--capture=no`` or ``-s`` Do not capture stdout
53+
``--high-memory`` Enable tests that use a large amount of memory (>0.5GiB)
5354
============================= ===========
5455

5556
To run a single test from the command line, you can provide a file path, optionally

lib/matplotlib/testing/conftest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@
44
from matplotlib import _api
55

66

7+
def pytest_addoption(parser):
8+
from matplotlib.testing import is_ci_environment
9+
10+
if not hasattr(pytest_addoption, 'called'):
11+
parser.addoption('--high-memory', action='store_true', dest='high_memory',
12+
default=is_ci_environment(),
13+
help='enable tests using large amounts of memory')
14+
# Ensure we don't get called twice if loaded from matplotlib+mpl_toolkits.
15+
pytest_addoption.called = True
16+
17+
718
def pytest_configure(config):
819
# config is initialized here rather than in pytest.ini so that `pytest
920
# --pyargs matplotlib` (which would not find pytest.ini) works. The only
@@ -80,6 +91,13 @@ def mpl_test_settings(request):
8091
matplotlib.use(prev_backend)
8192

8293

94+
@pytest.fixture
95+
def high_memory(pytestconfig):
96+
if not pytestconfig.getoption('high_memory'):
97+
pytest.skip('Test uses too much memory')
98+
yield
99+
100+
83101
@pytest.fixture
84102
def pd():
85103
"""

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_addoption, 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
@@ -320,7 +320,7 @@ def test_draw_path_collection_error_handling():
320320
fig.canvas.draw()
321321

322322

323-
def test_chunksize_fails():
323+
def test_chunksize_fails(high_memory):
324324
# NOTE: This test covers multiple independent test scenarios in a single
325325
# function, because each scenario uses ~2GB of memory and we don't
326326
# 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
@@ -1547,7 +1547,7 @@ def test_upsample_interpolation_stage(fig_test, fig_ref):
15471547

15481548

15491549
@check_figures_equal()
1550-
def test_downsample_interpolation_stage(fig_test, fig_ref):
1550+
def test_downsample_interpolation_stage(fig_test, fig_ref, high_memory):
15511551
"""
15521552
Show that interpolation_stage='auto' gives the same as 'rgba'
15531553
for downsampling.
@@ -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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_segment_hits():
3434
# Runtimes on a loaded system are inherently flaky. Not so much that a rerun
3535
# won't help, hopefully.
3636
@pytest.mark.flaky(reruns=5)
37-
def test_invisible_Line_rendering():
37+
def test_invisible_Line_rendering(high_memory):
3838
"""
3939
GitHub issue #1256 identified a bug in Line.draw method
4040

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_addoption, 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_addoption, 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_addoption, pytest_configure, pytest_unconfigure,
3+
high_memory, mpl_test_settings)

0 commit comments

Comments
 (0)