Skip to content

Commit 8b68724

Browse files
authored
skip tests if the dependencies are not available (#85)
* add skip decorators for dask, scipy, and bottleneck * use the decorators * require dask.array
1 parent fea34b2 commit 8b68724

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

pint_xarray/tests/test_accessors.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@
88

99
from .. import accessors, conversion
1010
from ..errors import DimensionalityError
11-
from .utils import assert_equal, assert_identical, assert_units_equal, raises_regex
11+
from .utils import (
12+
assert_equal,
13+
assert_identical,
14+
assert_units_equal,
15+
raises_regex,
16+
requires_bottleneck,
17+
requires_dask_array,
18+
requires_scipy,
19+
)
1220

1321
pytestmark = [
1422
pytest.mark.filterwarnings("error::pint.UnitStrippedWarning"),
@@ -814,6 +822,7 @@ def test_drop_sel(obj, indexers, expected, error):
814822
assert_identical(actual, expected)
815823

816824

825+
@requires_dask_array
817826
@pytest.mark.parametrize(
818827
"obj",
819828
(
@@ -1144,6 +1153,7 @@ def test_reindex_like(obj, other, expected, error):
11441153
assert_identical(actual, expected)
11451154

11461155

1156+
@requires_scipy
11471157
@pytest.mark.parametrize(
11481158
["obj", "indexers", "expected", "error"],
11491159
(
@@ -1307,6 +1317,7 @@ def test_interp(obj, indexers, expected, error):
13071317
assert_identical(actual, expected)
13081318

13091319

1320+
@requires_scipy
13101321
@pytest.mark.parametrize(
13111322
["obj", "other", "expected", "error"],
13121323
(
@@ -1504,6 +1515,7 @@ def test_interp_like(obj, other, expected, error):
15041515
assert_identical(actual, expected)
15051516

15061517

1518+
@requires_bottleneck
15071519
@pytest.mark.parametrize(
15081520
["obj", "expected"],
15091521
(
@@ -1598,6 +1610,7 @@ def test_ffill(obj, expected):
15981610
assert_units_equal(actual, expected)
15991611

16001612

1613+
@requires_bottleneck
16011614
@pytest.mark.parametrize(
16021615
["obj", "expected"],
16031616
(

pint_xarray/tests/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@
1616
)
1717

1818

19+
def importorskip(name):
20+
try:
21+
__import__(name)
22+
has_name = True
23+
except ImportError:
24+
has_name = False
25+
26+
return has_name, pytest.mark.skipif(not has_name, reason=f"{name} is not available")
27+
28+
29+
has_dask_array, requires_dask_array = importorskip("dask.array")
30+
has_scipy, requires_scipy = importorskip("scipy")
31+
has_bottleneck, requires_bottleneck = importorskip("bottleneck")
32+
33+
1934
@contextmanager
2035
def raises_regex(error, pattern):
2136
__tracebackhide__ = True

0 commit comments

Comments
 (0)