File tree Expand file tree Collapse file tree 2 files changed +22
-11
lines changed Expand file tree Collapse file tree 2 files changed +22
-11
lines changed Original file line number Diff line number Diff line change 1
1
""" Network tests are only run, if data is already locally available,
2
2
or if download is specifically requested by environment variable."""
3
+ import builtins
3
4
from os import environ
4
5
import pytest
5
6
from sklearn .datasets import fetch_20newsgroups
@@ -59,3 +60,16 @@ def fetch_olivetti_faces_fxt():
59
60
@pytest .fixture
60
61
def fetch_rcv1_fxt ():
61
62
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 )
Original file line number Diff line number Diff line change @@ -27,14 +27,11 @@ def test_fetch_asframe(fetch_california_housing_fxt):
27
27
assert isinstance (bunch .target , pd .Series )
28
28
29
29
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 )
You can’t perform that action at this time.
0 commit comments