8000 TST Enable california_housing pandas test in cron job (#16547) · ashutosh1919/scikit-learn@43293a6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 43293a6

Browse files
rthashutosh1919
authored andcommitted
TST Enable california_housing pandas test in cron job (scikit-learn#16547)
1 parent fdbff6c commit 43293a6

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

sklearn/datasets/tests/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
""" Network tests are only run, if data is already locally available,
22
or if download is specifically requested by environment variable."""
3+
import builtins
34
from os import environ
45
import pytest
56
from sklearn.datasets import fetch_20newsgroups
@@ -59,3 +60,16 @@ def fetch_olivetti_faces_fxt():
5960
@pytest.fixture
6061
def fetch_rcv1_fxt():
6162
return _wrapped_fetch(fetch_rcv1, dataset_name='rcv1')
63+
64+
65+
@pytest.fixture
66+
def hide_available_pandas(monkeypatch):
67+
""" Pretend pandas was not installed. """
68+
import_orig = builtins.__import__
69+
70+
def mocked_import(name, *args, **kwargs):
71+
if name == 'pandas':
72+
raise ImportError()
73+
return import_orig(name, *args, **kwargs)
74+
75+
monkeypatch.setattr(builtins, '__import__', mocked_import)

sklearn/datasets/tests/test_california_housing.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,11 @@ def test_fetch_asframe(fetch_california_housing_fxt):
2727
assert isinstance(bunch.target, pd.Series)
2828

2929

30-
def test_pandas_dependency_message(fetch_california_housing_fxt):
31-
try:
32-
import pandas # noqa
33-
pytest.skip("This test requires pandas to be not installed")
34-
except ImportError:
35-
# Check that pandas is imported lazily and that an informative error
36-
# message is raised when pandas is missing:
37-
expected_msg = ('fetch_california_housing with as_frame=True'
38-
' requires pandas')
39-
with pytest.raises(ImportError, match=expected_msg):
40-
fetch_california_housing_fxt(as_frame=True)
30+
def test_pandas_dependency_message(fetch_california_housing_fxt,
31+
hide_available_pandas):
32+
# Check that pandas is imported lazily and that an informative error
33+
# message is raised when pandas is missing:
34+
expected_msg = ('fetch_california_housing with as_frame=True'
35+
' requires pandas')
36+
with pytest.raises(ImportError, match=expected_msg):
37+
fetch_california_housing_fxt(as_frame=True)

0 commit comments

Comments
 (0)
0