Skip to content

Commit 1c4846a

Browse files
committed
Tests: use pytest.skip instead of silently ignoring tests.
1 parent 866a884 commit 1c4846a

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

tests/test_external.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
import os.path
22
from .utils import build_figure, clean_dir
3+
import pytest
34

4-
base = os.path.normpath(os.path.dirname(__file__))
5+
srcdir = os.path.join(os.path.normpath(os.path.dirname(__file__)), "sources", "external")
56

6-
try:
7-
import cartopy
8-
except ImportError:
9-
cartopy = None
107

11-
try:
12-
import seaborn
13-
except ImportError:
14-
seaborn = None
8+
def test_cartopy():
9+
"""Check a cartopy figure can be generated..."""
10+
try:
11+
import cartopy
12+
except ImportError:
13+
pytest.skip("cartopy not available for testing")
1514

15+
res = build_figure(srcdir, "cartopy_figure.py")
16+
assert res.returncode == 0, "tests/sources/external/cartopy_figure.py could not be built."
17+
clean_dir(srcdir)
1618

17-
if cartopy:
18-
def test_cartopy():
19-
"""Check a cartopy figure can be generated..."""
20-
dir = os.path.join(base, "sources", "external")
21-
res = build_figure(dir, "cartopy_figure.py")
22-
assert res.returncode == 0, "tests/sources/external/cartopy_figure.py could not be built."
23-
clean_dir(dir)
2419

20+
def test_seaborn():
21+
"""Check a seaborn figure can be generated..."""
22+
try:
23+
import seaborn
24+
except ImportError:
25+
pytest.skip("seaborn not available for testing")
2526

26-
if seaborn:
27-
def test_seaborn():
28-
"""Check a seaborn figure can be generated..."""
29-
dir = os.path.join(base, "sources", "external")
30-
res = build_figure(dir, "seaborn_figure.py")
31-
assert res.returncode == 0, "tests/sources/external/seaborn_figure.py could not be built."
32-
clean_dir(dir)
27+
res = build_figure(srcdir, "seaborn_figure.py")
28+
assert res.returncode == 0, "tests/sources/external/seaborn_figure.py could not be built."
29+
clean_dir(srcdir)
3330

0 commit comments

Comments
 (0)