Skip to content

Commit 45940b2

Browse files
committed
skip test if dataset is not available in test env
1 parent 19ed2f3 commit 45940b2

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

sklearn/datasets/tests/test_california_housing.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@ def fetch(*args, **kwargs):
1515
return fetch_california_housing(*args, download_if_missing=False, **kwargs)
1616

1717

18-
def test_fetch():
18+
def _is_california_housing_dataset_not_available():
1919
try:
20-
data = fetch()
20+
fetch_california_housing(download_if_missing=False)
21+
return False
2122
except IOError:
22-
raise SkipTest("California housing dataset can not be loaded.")
23+
return True
24+
25+
26+
@pytest.mark.skipif(
27+
_is_california_housing_dataset_not_available(),
28+
reason='Download California Housing dataset to run this test'
29+
)
30+
def test_fetch():
31+
data = fetch()
2332
assert((20640, 8) == data.data.shape)
2433
assert((20640, ) == data.target.shape)
2534

@@ -28,6 +37,10 @@ def test_fetch():
2837
check_return_X_y(data, fetch_func)
2938

3039

40+
@pytest.mark.skipif(
41+
_is_california_housing_dataset_not_available(),
42+
reason='Download California Housing dataset to run this test'
43+
)
3144
def test_fetch_asframe():
3245
pd = pytest.importorskip('pandas')
3346
bunch = fetch(as_frame=True)

0 commit comments

Comments
 (0)