Skip to content

Commit 038c5cd

Browse files
thomasjpfanogrisel
andauthored
MAINT Move conftest up a level (scikit-learn#20208)
Co-authored-by: Olivier Grisel <[email protected]>
1 parent e71ae40 commit 038c5cd

File tree

2 files changed

+64
-85
lines changed

2 files changed

+64
-85
lines changed

Diff for: conftest.py

-85
Original file line numberDiff line numberDiff line change
@@ -4,88 +4,3 @@
44
# details. For example, this allows to build extensions in place and run pytest
55
# doc/modules/clustering.rst and use sklearn from the local folder rather than
66
# the one from site-packages.
7-
8-
import platform
9-
import sys
10-
11-
import pytest
12-
from _pytest.doctest import DoctestItem
13-
14-
from sklearn.utils import _IS_32BIT
15-
from sklearn.externals import _pilutil
16-
from sklearn._min_dependencies import PYTEST_MIN_VERSION
17-
from sklearn.utils.fixes import np_version, parse_version
18-
19-
if parse_version(pytest.__version__) < parse_version(PYTEST_MIN_VERSION):
20-
raise ImportError('Your version of pytest is too old, you should have '
21-
'at least pytest >= {} installed.'
22-
.format(PYTEST_MIN_VERSION))
23-
24-
25-
def pytest_collection_modifyitems(config, items):
26-
for item in items:
27-
# FeatureHasher is not compatible with PyPy
28-
if (item.name.endswith(('_hash.FeatureHasher',
29-
'text.HashingVectorizer'))
30-
and platform.python_implementation() == 'PyPy'):
31-
marker = pytest.mark.skip(
32-
reason='FeatureHasher is not compatible with PyPy')
33-
item.add_marker(marker)
34-
# Known failure on with GradientBoostingClassifier on ARM64
35-
elif (item.name.endswith('GradientBoostingClassifier')
36-
and platform.machine() == 'aarch64'):
37-
38-
marker = pytest.mark.xfail(
39-
reason=(
40-
'know failure. See '
41-
'https://github.com/scikit-learn/scikit-learn/issues/17797' # noqa
42-
)
43-
)
44-
item.add_marker(marker)
45-
46-
# numpy changed the str/repr formatting of numpy arrays in 1.14. We want to
47-
# run doctests only for numpy >= 1.14.
48-
skip_doctests = False
49-
try:
50-
if np_version < parse_version('1.14'):
51-
reason = 'doctests are only run for numpy >= 1.14'
52-
skip_doctests = True
53-
elif _IS_32BIT:
54-
reason = ('doctest are only run when the default numpy int is '
55-
'64 bits.')
56-
skip_doctests = True
57-
elif sys.platform.startswith("win32"):
58-
reason = ("doctests are not run for Windows because numpy arrays "
59-
"repr is inconsistent across platforms.")
60-
skip_doctests = True
61-
except ImportError:
62-
pass
63-
64-
if skip_doctests:
65-
skip_marker = pytest.mark.skip(reason=reason)
66-
67-
for item in items:
68-
if isinstance(item, DoctestItem):
69-
item.add_marker(skip_marker)
70-
elif not _pilutil.pillow_installed:
71-
skip_marker = pytest.mark.skip(reason="pillow (or PIL) not installed!")
72-
for item in items:
73-
if item.name in [
74-
"sklearn.feature_extraction.image.PatchExtractor",
75-
"sklearn.feature_extraction.image.extract_patches_2d"]:
76-
item.add_marker(skip_marker)
77-
78-
79-
def pytest_configure(config):
80-
import sys
81-
sys._is_pytest_session = True
82-
# declare our custom markers to avoid PytestUnknownMarkWarning
83-
config.addinivalue_line(
84-
"markers",
85-
"network: mark a test for execution if network available."
86-
)
87-
88-
89-
def pytest_unconfigure(config):
90-
import sys
91-
del sys._is_pytest_session

Diff for: sklearn/conftest.py

+64
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import os
22
from os import environ
33
from functools import wraps
4+
import platform
5+
import sys
46

57
import pytest
68
from threadpoolctl import threadpool_limits
9+
from _pytest.doctest import DoctestItem
710

11+
from sklearn.utils import _IS_32BIT
812
from sklearn.utils._openmp_helpers import _openmp_effective_n_threads
13+
from sklearn.externals import _pilutil
14+
from sklearn._min_dependencies import PYTEST_MIN_VERSION
15+
from sklearn.utils.fixes import np_version, parse_version
916
from sklearn.datasets import fetch_20newsgroups
1017
from sklearn.datasets import fetch_20newsgroups_vectorized
1118
from sklearn.datasets import fetch_california_housing
@@ -15,6 +22,11 @@
1522
from sklearn.datasets import fetch_rcv1
1623

1724

25+
if parse_version(pytest.__version__) < parse_version(PYTEST_MIN_VERSION):
26+
raise ImportError('Your version of pytest is too old, you should have '
27+
'at least pytest >= {} installed.'
28+
.format(PYTEST_MIN_VERSION))
29+
1830
dataset_fetchers = {
1931
'fetch_20newsgroups_fxt': fetch_20newsgroups,
2032
'fetch_20newsgroups_vectorized_fxt': fetch_20newsgroups_vectorized,
@@ -93,6 +105,58 @@ def pytest_collection_modifyitems(config, items):
93105
for name in datasets_to_download:
94106
dataset_fetchers[name]()
95107

108+
for item in items:
109+
# FeatureHasher is not compatible with PyPy
110+
if (item.name.endswith(('_hash.FeatureHasher',
111+
'text.HashingVectorizer'))
112+
and platform.python_implementation() == 'PyPy'):
113+
marker = pytest.mark.skip(
114+
reason='FeatureHasher is not compatible with PyPy')
115+
item.add_marker(marker)
116+
# Known failure on with GradientBoostingClassifier on ARM64
117+
elif (item.name.endswith('GradientBoostingClassifier')
118+
and platform.machine() == 'aarch64'):
119+
120+
marker = pytest.mark.xfail(
121+
reason=(
122+
'know failure. See '
123+
'https://github.com/scikit-learn/scikit-learn/issues/17797' # noqa
124+
)
125+
)
126+
item.add_marker(marker)
127+
128+
# numpy changed the str/repr formatting of numpy arrays in 1.14. We want to
129+
# run doctests only for numpy >= 1.14.
130+
skip_doctests = False
131+
try:
132+
if np_version < parse_version('1.14'):
133+
reason = 'doctests are only run for numpy >= 1.14'
134+
skip_doctests = True
135+
elif _IS_32BIT:
136+
reason = ('doctest are only run when the default numpy int is '
137+
'64 bits.')
138+
skip_doctests = True
139+
elif sys.platform.startswith("win32"):
140+
reason = ("doctests are not run for Windows because numpy arrays "
141+
"repr is inconsistent across platforms.")
142+
skip_doctests = True
143+
except ImportError:
144+
pass
145+
146+
if skip_doctests:
147+
skip_marker = pytest.mark.skip(reason=reason)
148+
149+
for item in items:
150+
if isinstance(item, DoctestItem):
151+
item.add_marker(skip_marker)
152+
elif not _pilutil.pillow_installed:
153+
skip_marker = pytest.mark.skip(reason="pillow (or PIL) not installed!")
154+
for item in items:
155+
if item.name in [
156+
"sklearn.feature_extraction.image.PatchExtractor",
157+
"sklearn.feature_extraction.image.extract_patches_2d"]:
158+
item.add_marker(skip_marker)
159+
96160

97161
@pytest.fixture(scope='function')
98162
def pyplot():

0 commit comments

Comments
 (0)