Skip to content

Commit fa8f1aa

Browse files
committed
Use skipif instead of xfail when test dependencies are missing.
In such cases, there's no need to even try running the test and get an exception out of it.
1 parent 4769f7b commit fa8f1aa

File tree

6 files changed

+11
-20
lines changed

6 files changed

+11
-20
lines changed

lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
_determinism_check)
1515

1616

17-
needs_usetex = pytest.mark.xfail(
17+
needs_usetex = pytest.mark.skipif(
1818
not checkdep_usetex(True),
1919
reason="This test needs a TeX installation")
2020

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@
1515
_determinism_check)
1616

1717

18-
needs_ghostscript = pytest.mark.xfail(
18+
needs_ghostscript = pytest.mark.skipif(
1919
matplotlib.checkdep_ghostscript()[0] is None,
2020
reason="This test needs a ghostscript installation")
21-
22-
23-
needs_usetex = pytest.mark.xfail(
21+
needs_usetex = pytest.mark.skipif(
2422
not matplotlib.checkdep_usetex(True),
2523
reason="This test needs a TeX installation")
2624

lib/matplotlib/tests/test_backend_qt4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
py_qt_ver = QtCore.__version_info__[0]
2525

2626
if py_qt_ver != 4:
27-
pytestmark = pytest.mark.xfail(reason='Qt4 is not available')
27+
pytestmark = pytest.mark.skipif(reason='Qt4 is not available')
2828

2929

3030
@pytest.mark.backend('Qt4Agg')

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from matplotlib import dviread
1313

1414

15-
needs_usetex = pytest.mark.xfail(
15+
needs_usetex = pytest.mark.skipif(
1616
not matplotlib.checkdep_usetex(True),
1717
reason="This test needs a TeX installation")
1818

lib/matplotlib/tests/test_image.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@
2121
import pytest
2222

2323

24-
try:
25-
from PIL import Image
26-
HAS_PIL = True
27-
except ImportError:
28-
HAS_PIL = False
29-
needs_pillow = pytest.mark.xfail(not HAS_PIL, reason='Test requires Pillow')
30-
31-
3224
@image_comparison(baseline_images=['image_interps'], style='mpl20')
3325
def test_image_interps():
3426
'make the basic nearest, bilinear and bicubic interps'
@@ -111,17 +103,17 @@ def test_image_python_io():
111103
plt.imread(buffer)
112104

113105

114-
@needs_pillow
115106
def test_imread_pil_uint16():
107+
pytest.importorskip("PIL")
116108
img = plt.imread(os.path.join(os.path.dirname(__file__),
117109
'baseline_images', 'test_image', 'uint16.tif'))
118110
assert img.dtype == np.uint16
119111
assert np.sum(img) == 134184960
120112

121113

122114
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires Python 3.6+")
123-
@needs_pillow
124115
def test_imread_fspath():
116+
pytest.importorskip("PIL")
125117
from pathlib import Path
126118
img = plt.imread(
127119
Path(__file__).parent / 'baseline_images/test_image/uint16.tif')
@@ -498,8 +490,8 @@ def test_nonuniformimage_setnorm():
498490
im.set_norm(plt.Normalize())
499491

500492

501-
@needs_pillow
502493
def test_jpeg_2d():
494+
Image = pytest.importorskip('PIL.Image')
503495
# smoke test that mode-L pillow images work.
504496
imd = np.ones((10, 10), dtype='uint8')
505497
for i in range(10):
@@ -510,8 +502,9 @@ def test_jpeg_2d():
510502
ax.imshow(im)
511503

512504

513-
@needs_pillow
514505
def test_jpeg_alpha():
506+
Image = pytest.importorskip('PIL.Image')
507+
515508
plt.figure(figsize=(1, 1), dpi=300)
516509
# Create an image that is all black, with a gradient from 0-1 in
517510
# the alpha channel from left to right.

lib/matplotlib/tests/test_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from matplotlib.testing.decorators import image_comparison
1111

1212

13-
needs_usetex = pytest.mark.xfail(
13+
needs_usetex = pytest.mark.skipif(
1414
not matplotlib.checkdep_usetex(True),
1515
reason="This test needs a TeX installation")
1616

0 commit comments

Comments
 (0)