forked from scikit-learn/scikit-learn
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
106 lines (82 loc) · 3.56 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Even if empty this file is useful so that when running from the root folder
# ./sklearn is added to sys.path by pytest. See
# https://docs.pytest.org/en/latest/pythonpath.html for more details. For
# example, this allows to build extensions in place and run pytest
# doc/modules/clustering.rst and use sklearn from the local folder rather than
# the one from site-packages.
importplatform
fromdistutils.versionimportLooseVersion
importos
importpytest
from_pytest.doctestimportDoctestItem
fromsklearnimportset_config
fromsklearn.utilsimport_IS_32BIT
fromsklearn.externalsimport_pilutil
fromsklearn._build_utils.deprecated_modulesimport_DEPRECATED_MODULES
PYTEST_MIN_VERSION='3.3.0'
ifLooseVersion(pytest.__version__) <PYTEST_MIN_VERSION:
raiseImportError('Your version of pytest is too old, you should have '
'at least pytest >= {} installed.'
.format(PYTEST_MIN_VERSION))
defpytest_addoption(parser):
parser.addoption("--skip-network", action="store_true", default=False,
help="skip network tests")
defpytest_collection_modifyitems(config, items):
# FeatureHasher is not compatible with PyPy
ifplatform.python_implementation() =='PyPy':
skip_marker=pytest.mark.skip(
reason='FeatureHasher is not compatible with PyPy')
foriteminitems:
ifitem.name.endswith(('hashing.FeatureHasher',
'text.HashingVectorizer')):
item.add_marker(skip_marker)
# Skip tests which require internet if the flag is provided
ifconfig.getoption("--skip-network"):
skip_network=pytest.mark.skip(
reason="test requires internet connectivity")
foriteminitems:
if"network"initem.keywords:
item.add_marker(skip_network)
# numpy changed the str/repr formatting of numpy arrays in 1.14. We want to
# run doctests only for numpy >= 1.14.
skip_doctests=False
try:
importnumpyasnp
ifLooseVersion(np.__version__) <LooseVersion('1.14'):
reason='doctests are only run for numpy >= 1.14'
skip_doctests=True
elif_IS_32BIT:
reason= ('doctest are only run when the default numpy int is '
'64 bits.')
skip_doctests=True
exceptImportError:
pass
ifskip_doctests:
skip_marker=pytest.mark.skip(reason=reason)
foriteminitems:
ifisinstance(item, DoctestItem):
item.add_marker(skip_marker)
elifnot_pilutil.pillow_installed:
skip_marker=pytest.mark.skip(reason="pillow (or PIL) not installed!")
foriteminitems:
ifitem.namein [
"sklearn.feature_extraction.image.PatchExtractor",
"sklearn.feature_extraction.image.extract_patches_2d"]:
item.add_marker(skip_marker)
defpytest_configure(config):
importsys
sys._is_pytest_session=True
defpytest_unconfigure(config):
importsys
delsys._is_pytest_session
defpytest_runtest_setup(item):
ifisinstance(item, DoctestItem):
set_config(print_changed_only=True)
defpytest_runtest_teardown(item, nextitem):
ifisinstance(item, DoctestItem):
set_config(print_changed_only=False)
# TODO: Remove when modules are deprecated in 0.24
# Configures pytest to ignore deprecated modules.
collect_ignore_glob= [
os.path.join(*deprecated_path.split(".")) +".py"
for_, deprecated_path, _, _in_DEPRECATED_MODULES]