1 Star 0 Fork 0

chenglibo/scikit-learn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
conftest.py 3.97 KB
一键复制 编辑 原始数据 按行查看 历史
# 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.
import platform
import sys
from distutils.version import LooseVersion
import os
import pytest
from _pytest.doctest import DoctestItem
from sklearn import set_config
from sklearn.utils import _IS_32BIT
from sklearn.externals import _pilutil
from sklearn._build_utils.deprecated_modules import _DEPRECATED_MODULES
PYTEST_MIN_VERSION = '3.3.0'
if LooseVersion(pytest.__version__) < PYTEST_MIN_VERSION:
raise ImportError('Your version of pytest is too old, you should have '
'at least pytest >= {} installed.'
.format(PYTEST_MIN_VERSION))
def pytest_addoption(parser):
parser.addoption("--skip-network", action="store_true", default=False,
help="skip network tests")
def pytest_collection_modifyitems(config, items):
# FeatureHasher is not compatible with PyPy
if platform.python_implementation() == 'PyPy':
skip_marker = pytest.mark.skip(
reason='FeatureHasher is not compatible with PyPy')
for item in items:
if item.name.endswith(('_hash.FeatureHasher',
'text.HashingVectorizer')):
item.add_marker(skip_marker)
# Skip tests which require internet if the flag is provided
if config.getoption("--skip-network"):
skip_network = pytest.mark.skip(
reason="test requires internet connectivity")
for item in items:
if "network" in item.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:
import numpy as np
if LooseVersion(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
elif sys.platform.startswith("win32"):
reason = ("doctests are not run for Windows because numpy arrays "
"repr is inconsistent across platforms.")
skip_doctests = True
except ImportError:
pass
if skip_doctests:
skip_marker = pytest.mark.skip(reason=reason)
for item in items:
if isinstance(item, DoctestItem):
item.add_marker(skip_marker)
elif not _pilutil.pillow_installed:
skip_marker = pytest.mark.skip(reason="pillow (or PIL) not installed!")
for item in items:
if item.name in [
"sklearn.feature_extraction.image.PatchExtractor",
"sklearn.feature_extraction.image.extract_patches_2d"]:
item.add_marker(skip_marker)
def pytest_configure(config):
import sys
sys._is_pytest_session = True
# declare our custom markers to avoid PytestUnknownMarkWarning
config.addinivalue_line(
"markers",
"network: mark a test for execution if network available."
)
def pytest_unconfigure(config):
import sys
del sys._is_pytest_session
def pytest_runtest_setup(item):
if isinstance(item, DoctestItem):
set_config(print_changed_only=True)
def pytest_runtest_teardown(item, nextitem):
if isinstance(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]
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chenglibo/scikit-learn.git
git@gitee.com:chenglibo/scikit-learn.git
chenglibo
scikit-learn
scikit-learn
master

搜索帮助