diff --git a/continuous_integration/test_script.sh b/continuous_integration/test_script.sh index 23ea610ab5258..04ec2b5318499 100644 --- a/continuous_integration/test_script.sh +++ b/continuous_integration/test_script.sh @@ -11,6 +11,11 @@ python -c "import numpy; print('numpy %s' % numpy.__version__)" python -c "import scipy; print('scipy %s' % scipy.__version__)" python setup.py build_ext --inplace +# Skip tests that require large downloads over the network to save bandwith +# usage as travis workers are stateless and therefore traditional local +# disk caching does not work. +export SKLEARN_SKIP_NETWORK_TESTS=1 + if [[ "$COVERAGE" == "true" ]]; then make test-coverage else diff --git a/doc/tutorial/text_analytics/working_with_text_data_fixture.py b/doc/tutorial/text_analytics/working_with_text_data_fixture.py new file mode 100644 index 0000000000000..295e55c3be9ca --- /dev/null +++ b/doc/tutorial/text_analytics/working_with_text_data_fixture.py @@ -0,0 +1,15 @@ +"""Fixture module to skip the datasets loading when offline + +The 20 newsgroups data is rather large and some CI workers such as travis are +stateless hence will not cache the dataset as regular sklearn users would do. + +The following will skip the execution of the working_with_text_data.rst doctests +is the proper environment variable is configured (see the source code of +check_skip_network for more details). + +""" +from sklearn.utils.testing import check_skip_network + + +def setup_module(): + check_skip_network() diff --git a/sklearn/utils/testing.py b/sklearn/utils/testing.py index 769bead18fefb..f3ee830c64f10 100644 --- a/sklearn/utils/testing.py +++ b/sklearn/utils/testing.py @@ -8,6 +8,7 @@ # Arnaud Joly # Denis Engemann # License: BSD 3 clause +import os import inspect import pkgutil import warnings @@ -594,3 +595,11 @@ def clean_warning_registry(): for mod in sys.modules.copy().values(): if hasattr(mod, reg): getattr(mod, reg).clear() + + +def check_skip_network(): + if int(os.environ.get('SKLEARN_SKIP_NETWORK_TESTS', 0)): + raise SkipTest("Text tutorial requires large dataset download") + + +with_network = with_setup(check_skip_network)