Skip to content

Commit 209d1dc

Browse files
anntzerArchangeGabriel
authored andcommitted
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 9f4a442 commit 209d1dc

File tree

6 files changed

+11
-20
lines changed

6 files changed

+11
-20
lines changed

lib/matplotlib/tests/test_backend_pdf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
_determinism_check)
2121

2222

23-
needs_usetex = pytest.mark.xfail(
23+
needs_usetex = pytest.mark.skipif(
2424
not checkdep_usetex(True),
2525
reason="This test needs a TeX installation")
2626

lib/matplotlib/tests/test_backend_ps.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
_determinism_check)
1818

1919

20-
needs_ghostscript = pytest.mark.xfail(
20+
needs_ghostscript = pytest.mark.skipif(
2121
matplotlib.checkdep_ghostscript()[0] is None,
2222
reason="This test needs a ghostscript installation")
23-
24-
25-
needs_usetex = pytest.mark.xfail(
23+
needs_usetex = pytest.mark.skipif(
2624
not matplotlib.checkdep_usetex(True),
2725
reason="This test needs a TeX installation")
2826

lib/matplotlib/tests/test_backend_qt4.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
py_qt_ver = QtCore.__version_info__[0]
3030

3131
if py_qt_ver != 4:
32-
pytestmark = pytest.mark.xfail(reason='Qt4 is not available')
32+
pytestmark = pytest.mark.skipif(reason='Qt4 is not available')
3333

3434

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

lib/matplotlib/tests/test_backend_svg.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from matplotlib import dviread
1717

1818

19-
needs_usetex = pytest.mark.xfail(
19+
needs_usetex = pytest.mark.skipif(
2020
not matplotlib.checkdep_usetex(True),
2121
reason="This test needs a TeX installation")
2222

lib/matplotlib/tests/test_image.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@
2323
import pytest
2424

2525

26-
try:
27-
from PIL import Image
28-
HAS_PIL = True
29-
except ImportError:
30-
HAS_PIL = False
31-
needs_pillow = pytest.mark.xfail(not HAS_PIL, reason='Test requires Pillow')
32-
33-
3426
@image_comparison(baseline_images=['image_interps'], style='mpl20')
3527
def test_image_interps():
3628
'make the basic nearest, bilinear and bicubic interps'
@@ -113,17 +105,17 @@ def test_image_python_io():
113105
plt.imread(buffer)
114106

115107

116-
@needs_pillow
117108
def test_imread_pil_uint16():
109+
pytest.importorskip("PIL")
118110
img = plt.imread(os.path.join(os.path.dirname(__file__),
119111
'baseline_images', 'test_image', 'uint16.tif'))
120112
assert (img.dtype == np.uint16)
121113
assert np.sum(img) == 134184960
122114

123115

124116
@pytest.mark.skipif(sys.version_info < (3, 6), reason="requires Python 3.6+")
125-
@needs_pillow
126117
def test_imread_fspath():
118+
pytest.importorskip("PIL")
127119
from pathlib import Path
128120
img = plt.imread(
129121
Path(__file__).parent / 'baseline_images/test_image/uint16.tif')
@@ -497,8 +489,8 @@ def test_nonuniformimage_setnorm():
497489
im.set_norm(plt.Normalize())
498490

499491

500-
@needs_pillow
501492
def test_jpeg_2d():
493+
Image = pytest.importorskip('PIL.Image')
502494
# smoke test that mode-L pillow images work.
503495
imd = np.ones((10, 10), dtype='uint8')
504496
for i in range(10):
@@ -509,8 +501,9 @@ def test_jpeg_2d():
509501
ax.imshow(im)
510502

511503

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

lib/matplotlib/tests/test_text.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from matplotlib.testing.decorators import image_comparison
1515

1616

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

0 commit comments

Comments
 (0)