Skip to content

Commit a8b79bb

Browse files
authored
Merge pull request matplotlib#19173 from QuLogic/test-backends
Ensure backend tests are skipped if unavailable
2 parents 28b1f0a + c9e1cb5 commit a8b79bb

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

lib/matplotlib/tests/test_backend_qt.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ def qt_core(request):
3434

3535
@pytest.mark.parametrize('backend', [
3636
# Note: the value is irrelevant; the important part is the marker.
37-
pytest.param('Qt4Agg', marks=pytest.mark.backend('Qt4Agg')),
38-
pytest.param('Qt5Agg', marks=pytest.mark.backend('Qt5Agg')),
37+
pytest.param(
38+
'Qt4Agg',
39+
marks=pytest.mark.backend('Qt4Agg', skip_on_importerror=True)),
40+
pytest.param(
41+
'Qt5Agg',
42+
marks=pytest.mark.backend('Qt5Agg', skip_on_importerror=True)),
3943
])
4044
def test_fig_close(backend):
4145
# save the state of Gcf.figs
@@ -53,7 +57,7 @@ def test_fig_close(backend):
5357
assert init_figs == Gcf.figs
5458

5559

56-
@pytest.mark.backend('Qt5Agg')
60+
@pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
5761
def test_fig_signals(qt_core):
5862
# Create a figure
5963
plt.figure()
@@ -130,8 +134,12 @@ def CustomHandler(signum, frame):
130134
)
131135
@pytest.mark.parametrize('backend', [
132136
# Note: the value is irrelevant; the important part is the marker.
133-
pytest.param('Qt4Agg', marks=pytest.mark.backend('Qt4Agg')),
134-
pytest.param('Qt5Agg', marks=pytest.mark.backend('Qt5Agg')),
137+
pytest.param(
138+
'Qt4Agg',
139+
marks=pytest.mark.backend('Qt4Agg', skip_on_importerror=True)),
140+
pytest.param(
141+
'Qt5Agg',
142+
marks=pytest.mark.backend('Qt5Agg', skip_on_importerror=True)),
135143
])
136144
def test_correct_key(backend, qt_core, qt_key, qt_mods, answer):
137145
"""
@@ -157,7 +165,7 @@ def on_key_press(event):
157165
qt_canvas.keyPressEvent(_Event())
158166

159167

160-
@pytest.mark.backend('Qt5Agg')
168+
@pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
161169
def test_pixel_ratio_change():
162170
"""
163171
Make sure that if the pixel ratio changes, the figure dpi changes but the
@@ -229,7 +237,7 @@ def set_pixel_ratio(ratio):
229237
assert (fig.get_size_inches() == (5, 2)).all()
230238

231239

232-
@pytest.mark.backend('Qt5Agg')
240+
@pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
233241
def test_subplottool():
234242
fig, ax = plt.subplots()
235243
with mock.patch(
@@ -238,7 +246,7 @@ def test_subplottool():
238246
fig.canvas.manager.toolbar.configure_subplots()
239247

240248

241-
@pytest.mark.backend('Qt5Agg')
249+
@pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
242250
def test_figureoptions():
243251
fig, ax = plt.subplots()
244252
ax.plot([1, 2])
@@ -250,7 +258,7 @@ def test_figureoptions():
250258
fig.canvas.manager.toolbar.edit_parameters()
251259

252260

253-
@pytest.mark.backend('Qt5Agg')
261+
@pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
254262
def test_double_resize():
255263
# Check that resizing a figure twice keeps the same window size
256264
fig, ax = plt.subplots()
@@ -270,7 +278,7 @@ def test_double_resize():
270278
assert window.height() == old_height
271279

272280

273-
@pytest.mark.backend("Qt5Agg")
281+
@pytest.mark.backend('Qt5Agg', skip_on_importerror=True)
274282
def test_canvas_reinit():
275283
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg
276284

lib/matplotlib/tests/test_determinism.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ def test_determinism_check(objects, fmt, usetex):
100100
[sys.executable, "-R", "-c",
101101
f"from matplotlib.tests.test_determinism import _save_figure;"
102102
f"_save_figure({objects!r}, {fmt!r}, {usetex})"],
103-
env={**os.environ, "SOURCE_DATE_EPOCH": "946684800"})
103+
env={**os.environ, "SOURCE_DATE_EPOCH": "946684800",
104+
"MPLBACKEND": "Agg"})
104105
for _ in range(3)
105106
]
106107
for p in plots[1:]:
@@ -139,5 +140,6 @@ def test_determinism_source_date_epoch(fmt, string):
139140
[sys.executable, "-R", "-c",
140141
f"from matplotlib.tests.test_determinism import _save_figure; "
141142
f"_save_figure('', {fmt!r})"],
142-
env={**os.environ, "SOURCE_DATE_EPOCH": "946684800"})
143+
env={**os.environ, "SOURCE_DATE_EPOCH": "946684800",
144+
"MPLBACKEND": "Agg"})
143145
assert string in buf

lib/matplotlib/tests/test_matplotlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ def test_importable_with__OO():
5656
"import matplotlib.patches as mpatches"
5757
)
5858
cmd = [sys.executable, "-OO", "-c", program]
59-
assert subprocess.call(cmd) == 0
59+
assert subprocess.call(cmd, env={**os.environ, "MPLBACKEND": ""}) == 0

lib/matplotlib/tests/test_sphinxext.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for tinypages build using sphinx extensions."""
22

33
import filecmp
4+
import os
45
from pathlib import Path
56
from subprocess import Popen, PIPE
67
import sys
@@ -19,14 +20,14 @@ def test_tinypages(tmpdir):
1920
cmd = [sys.executable, '-msphinx', '-W', '-b', 'html',
2021
'-d', str(doctree_dir),
2122
str(Path(__file__).parent / 'tinypages'), str(html_dir)]
22-
proc = Popen(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True)
23+
proc = Popen(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True,
24+
env={**os.environ, "MPLBACKEND": ""})
2325
out, err = proc.communicate()
2426

2527
assert proc.returncode == 0, \
26-
"sphinx build failed with stdout:\n{}\nstderr:\n{}\n".format(out, err)
28+
f"sphinx build failed with stdout:\n{out}\nstderr:\n{err}\n"
2729
if err:
28-
pytest.fail("sphinx build emitted the following warnings:\n{}"
29-
.format(err))
30+
pytest.fail(f"sphinx build emitted the following warnings:\n{err}")
3031

3132
assert html_dir.is_dir()
3233

0 commit comments

Comments
 (0)