8000 [MRG+1] Remove nose from CIs and documentation (#9840) · scikit-learn/scikit-learn@e7e05d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit e7e05d8

Browse files
lesteverth
authored andcommitted
[MRG+1] Remove nose from CIs and documentation (#9840)
1 parent 2160ea0 commit e7e05d8

21 files changed

+89
-173
lines changed

.travis.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,19 @@ matrix:
4242
- env: DISTRIB="conda" PYTHON_VERSION="3.6.2" INSTALL_MKL="true"
4343
NUMPY_VERSION="1.13.1" SCIPY_VERSION="0.19.1" PANDAS_VERSION="0.20.3"
4444
CYTHON_VERSION="0.26.1" COVERAGE=true
45-
if: type != cron
46-
# This environment use pytest to run the tests. It uses the newest
47-
# supported Anaconda release (5.0.0). It also runs tests requiring Pandas.
48-
- env: USE_PYTEST="true" DISTRIB="conda" PYTHON_VERSION="3.6.2"
49-
INSTALL_MKL="true" NUMPY_VERSION="1.13.1" SCIPY_VERSION="0.19.1"
50-
PANDAS_VERSION="0.20.3" CYTHON_VERSION="0.26.1"
51-
TEST_DOCSTRINGS="true"
45+
CHECK_PYTEST_SOFT_DEPENDENCY="true"
5246
if: type != cron
5347
# flake8 linting on diff wrt common ancestor with upstream/master
5448
- env: RUN_FLAKE8="true" SKIP_TESTS="true"
5549
DISTRIB="conda" PYTHON_VERSION="3.5" INSTALL_MKL="true"
56-
NUMPY_VERSION="1.13.1" SCIPY_VERSION="0.19.1" CYTHON_VERSION="0.26.1"
50+
NUMPY_VERSION="1.13.1" SCIPY_VERSION="0.19.1"
51+
CYTHON_VERSION="0.26.1"
5752
if: type != cron
5853
# This environment tests scikit-learn aga 9E81 inst numpy and scipy master
5954
# installed from their CI wheels in a virtualenv with the Python
6055
# interpreter provided by travis.
6156
- python: 3.6
62-
env: USE_PYTEST="true" DISTRIB="scipy-dev-wheels"
57+
env: DISTRIB="scipy-dev-wheels"
6358
if: type = cron
6459

6560
install: source build_tools/travis/install.sh

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ tools:
139139
- Code with good unittest **coverage** (at least 80%), check with:
140140

141141
```bash
142-
$ pip install nose coverage
143-
$ nosetests --with-coverage path/to/tests_for_package
142+
$ pip install pytest pytest-cov
143+
$ pytest --cov sklearn path/to/tests_for_package
144144
```
145145

146146
- No pyflakes warnings, check with:

Makefile

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,12 @@
44

55
PYTHON ?= python
66
CYTHON ?= cython
7-
NOSETESTS ?= nosetests
7+
PYTEST ?= pytest
88
CTAGS ?= ctags
99

1010
# skip doctests on 32bit python
1111
BITS := $(shell python -c 'import struct; print(8 * struct.calcsize("P"))')
1212

13-
ifeq ($(BITS),32)
14-
NOSETESTS:=$(NOSETESTS) -c setup32.cfg
15-
endif
16-
17-
1813
all: clean inplace test
1914

2015
clean-ctags:
@@ -29,19 +24,17 @@ inplace:
2924
$(PYTHON) setup.py build_ext -i
3025

3126
test-code: in
32-
$(NOSETESTS) -s -v sklearn
27+
$(PYTEST) --showlocals -v sklearn
3328
test-sphinxext:
34-
$(NOSETESTS) -s -v doc/sphinxext/
29+
$(PYTEST) --showlocals -v doc/sphinxext/
3530
test-doc:
3631
ifeq ($(BITS),64)
37-
$(NOSETESTS) -s -v doc/*.rst doc/modules/ doc/datasets/ \
38-
doc/developers doc/tutorial/basic doc/tutorial/statistical_inference \
39-
doc/tutorial/text_analytics
32+
$(PYTEST) $(shell find doc -name '*.rst' | sort)
4033
endif
4134

4235
test-coverage:
4336
rm -rf coverage .coverage
44-
$(NOSETESTS) -s -v --with-coverage sklearn
37+
$(PYTEST) sklearn --show-locals -v --with-cov sklearn
4538

4639
test: test-code test-sphinxext test-doc
4740

README.rst

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,9 @@ Testing
110110
~~~~~~~
111111

112112
After installation, you can launch the test suite from outside the
113-
source directory (you will need to have the ``nose`` package installed)::
113+
source directory (you will need to have the ``pytest`` package installed)::
114114

115-
nosetests -v sklearn
116-
117-
Under Windows, it is recommended to use the following command (adjust the path
118-
to the ``python.exe`` program) as using the ``nosetests.exe`` program can badly
119-
interact with tests that use ``multiprocessing``::
120-
121-
C:\Python34\python.exe -c "import nose; nose.main()" -v sklearn
115+
pytest sklearn
122116

123117
See the web page http://scikit-learn.org/stable/developers/advanced_installation.html#testing
124118
for more information.

appveyor.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ build: false
7878
test_script:
7979
# Change to a non-source folder to make sure we run the tests on the
8080
# installed library.
81-
- "mkdir empty_folder"
82-
- "cd empty_folder"
83-
- "python -c \"import nose; nose.main()\" --with-timer --timer-top-n 20 -s sklearn"
84-
81+
- mkdir "../empty_folder"
82+
- cd "../empty_folder"
83+
- pytest --showlocals --durations=20 --pyargs sklearn
8584
# Move back to the project folder
86-
- "cd .."
85+
- cd "../scikit-learn"
8786

8887
artifacts:
8988
# Archive the generated wheel package in the ci.appveyor.com build report.

build_tools/appveyor/requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
numpy==1.9.3
1111
scipy==0.16.0
1212
cython
13-
nose
14-
nose-timer
13+
pytest
1514
wheel
1615
wheelhouse_uploader

build_tools/circle/build_doc.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ conda update --yes --quiet conda
107107
# Configure the conda environment and put it in the path using the
108108
# provided versions
109109
conda create -n $CONDA_ENV_NAME --yes --quiet python numpy scipy \
110-
cython nose coverage matplotlib sphinx=1.6.2 pillow
110+
cython pytest coverage matplotlib sphinx=1.6.2 pillow
111111
source activate testenv
112112
pip install sphinx-gallery
113113
# Use numpydoc master (for now)

build_tools/travis/after_success.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -e
88

99
if [[ "$COVERAGE" == "true" ]]; then
1010
# Need to run codecov from a git checkout, so we copy .coverage
11-
# from TEST_DIR where nosetests has been run
11+
# from TEST_DIR where pytest has been run
1212
cp $TEST_DIR/.coverage $TRAVIS_BUILD_DIR
1313
cd $TRAVIS_BUILD_DIR
1414
# Ignore codecov failures as the codecov server is not

build_tools/travis/install.sh

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,20 @@ if [[ "$DISTRIB" == "conda" ]]; then
3939

4040
# Configure the conda environment and put it in the path using the
4141
# provided versions
42-
if [[ "$USE_PYTEST" == "true" ]]; then
43-
TEST_RUNNER_PACKAGE=pytest
44-
else
45-
TEST_RUNNER_PACKAGE=nose
46-
fi
47-
4842
if [[ "$INSTALL_MKL" == "true" ]]; then
4943
conda create -n testenv --yes python=$PYTHON_VERSION pip \
50-
$TEST_RUNNER_PACKAGE numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION \
44+
pytest pytest-cov numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION \
5145
mkl cython=$CYTHON_VERSION \
5246
${PANDAS_VERSION+pandas=$PANDAS_VERSION}
5347

5448
else
5549
conda create -n testenv --yes python=$PYTHON_VERSION pip \
56-
$TEST_RUNNER_PACKAGE numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION \
50+
pytest pytest-cov numpy=$NUMPY_VERSION scipy=$SCIPY_VERSION \
5751
nomkl cython=$CYTHON_VERSION \
5852
${PANDAS_VERSION+pandas=$PANDAS_VERSION}
5953
fi
6054
source activate testenv
6155

62-
if [[ $USE_PYTEST != "true" ]]; then
63-
# Install nose-timer via pip
64-
pip install nose-timer
65-
fi
66-
6756
elif [[ "$DISTRIB" == "ubuntu" ]]; then
6857
# At the time of writing numpy 1.9.1 is included in the travis
6958
# virtualenv but we want to use the numpy installed through apt-get
@@ -73,7 +62,7 @@ elif [[ "$DISTRIB" == "ubuntu" ]]; then
7362
# and scipy
7463
virtualenv --system-site-packages testvenv
7564
source testvenv/bin/activate
76-
pip install nose nose-timer cython==$CYTHON_VERSION
65+
pip install pytest pytest-cov cython==$CYTHON_VERSION
7766

7867
elif [[ "$DISTRIB" == "scipy-dev-wheels" ]]; then
7968
# Set up our own virtualenv environment to avoid travis' numpy.
@@ -86,12 +75,7 @@ elif [[ "$DISTRIB" == "scipy-dev-wheels" ]]; then
8675
echo "Installing numpy and scipy master wheels"
8776
dev_url=https://7933911d6844c6c53a7d-47bd50c35cd79bd838daf386af554a83.ssl.cf2.rackcdn.com
8877
pip install --pre --upgrade --timeout=60 -f $dev_url numpy scipy pandas cython
89-
if [[ $USE_PYTEST == "true" ]]; then
90-
pip install pytest
91-
else
92-
# Install nose-timer via pip
93-
pip install nose nose-timer
94-
fi
78+
pip install pytest pytest-cov
9579
fi
9680

9781
if [[ "$COVERAGE" == "true" ]]; then
@@ -102,8 +86,8 @@ if [[ "$TEST_DOCSTRINGS" == "true" ]]; then
10286
pip install sphinx numpydoc # numpydoc requires sphinx
10387
fi
10488

105-
if [[ "$SKIP_TESTS" == "true" ]]; then
106-
echo "No need to build scikit-learn when not running the tests"
89+
if [[ "$SKIP_TESTS" == "true" && "$CHECK_PYTEST_SOFT_DEPENDENCY" != "true" ]]; then
90+
echo "No need to build scikit-learn"
10791
else
10892
# Build scikit-learn in the install.sh script to collapse the verbose
10993
# build output in the travis output when it succeeds.

build_tools/travis/test_script.sh

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@ except ImportError:
2121
python -c "import multiprocessing as mp; print('%d CPUs' % mp.cpu_count())"
2222

2323
run_tests() {
24-
if [[ "$USE_PYTEST" == "true" ]]; then
25-
TEST_CMD="pytest --showlocals --durations=20 --pyargs"
26-
else
27-
TEST_CMD="nosetests --with-timer --timer-top-n 20"
28-
fi
24+
TEST_CMD="pytest --showlocals --durations=20 --pyargs"
25+
2926
# Get into a temp directory to run test from the installed scikit-learn and
3027
# check if we do not leave artifacts
3128
mkdir -p $TEST_DIR
32-
# We need the setup.cfg for the nose settings
29+
# We need the setup.cfg for the pytest settings
3330
cp setup.cfg $TEST_DIR
3431
cd $TEST_DIR
3532

@@ -39,23 +36,18 @@ run_tests() {
3936
export SKLEARN_SKIP_NETWORK_TESTS=1
40< 10000 /td>37

4138
if [[ "$COVERAGE" == "true" ]]; then
42-
TEST_CMD="$TEST_CMD --with-coverage"
39+
TEST_CMD="$TEST_CMD --cov sklearn"
4340
fi
4441
$TEST_CMD sklearn
4542

4643
# Going back to git checkout folder needed to test documentation
4744
cd $OLDPWD
4845

49-
if [[ "$USE_PYTEST" == "true" ]]; then
50-
# Do not run doctests in scipy-dev-wheels build for now
51-
# (broken by numpy 1.14.dev array repr/str formatting
52-
# change even with np.set_printoptions(sign='legacy')).
53-
# See https://github.com/numpy/numpy/issues/9804 for more details
54-
if [[ "$DISTRIB" != "scipy-dev-wheels" ]]; then
55-
pytest $(find doc -name '*.rst' | sort)
56-
fi
57-
else
58-
# Makefile is using nose
46+
# Do not run doctests in scipy-dev-wheels build for now
47+
# (broken by numpy 1.14.dev array repr/str formatting
48+
# change even with np.set_printoptions(sign='legacy')).
49+
# See https://github.com/numpy/numpy/issues/9804 for more details
50+
if [[ "$DISTRIB" != "scipy-dev-wheels" ]]; then
5951
make test-doc
6052
fi
6153
}
@@ -67,3 +59,18 @@ fi
6759
if [[ "$SKIP_TESTS" != "true" ]]; then
6860
run_tests
6961
fi
62+
63+
if [[ "$CHECK_PYTEST_SOFT_DEPENDENCY" == "true" ]]; then
64+
conda remove -y py pytest || pip uninstall -y py pytest
65+
if [[ "$COVERAGE" == "true" ]]; then
66+
# Need to append the coverage to the existing .coverage generated by
67+
# running the tests
68+
CMD="coverage run --append"
69+
else
70+
CMD="python"
71+
fi
72+
# .coverage from running the tests is in TEST_DIR
73+
cd $TEST_DIR
74+
$CMD -m sklearn.utils.tests.test_estimator_checks
75+
cd $OLDPWD
76+
fi

doc/developers/advanced_installation.rst

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -376,24 +376,17 @@ Testing
376376
Testing scikit-learn once installed
377377
-----------------------------------
378378

379-
Testing requires having the `nose
380-
<https://nose.readthedocs.io/en/latest/>`_ library. After
379+
Testing requires having the `pytest
380+
<https://docs.pytest.org>`_ library. After
381381
installation, the package can be tested by executing *from outside* the
382382
source directory::
383383

384-
$ nosetests -v sklearn
385-
386-
Under Windows, it is recommended to use the following command (adjust the path
387-
to the ``python.exe`` program) as using the ``nosetests.exe`` program can badly
388-
interact with tests that use ``multiprocessing``::
389-
390-
C:\Python34\python.exe -c "import nose; nose.main()" -v sklearn
384+
$ pytest sklearn
391385

392386
This should give you a lot of output (and some warnings) but
393387
eventually should finish with a message similar to::
394388

395-
Ran 3246 tests in 260.618s
396-
OK (SKIP=20)
389+
=========== 8304 passed, 26 skipped, 4659 warnings in 557.76 seconds ===========
397390

398391
Otherwise, please consider posting an issue into the `bug tracker
399392
<https://github.com/scikit-learn/scikit-learn/issues>`_ or to the
@@ -411,9 +404,9 @@ source directory::
411404

412405
python setup.py build_ext --inplace
413406

414-
Test can now be run using nosetests::
407+
Test can now be run using pytest::
415408

416-
nosetests -v sklearn/
409+
pytest sklearn
417410

418411
This is automated by the commands::
419412

doc/developers/contributing.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ You can also check for common programming errors with the following tools:
280280
* Code with a good unittest coverage (at least 90%, better 100%), check
281281
with::
282282

283-
$ pip install nose coverage
284-
$ nosetests --with-coverage path/to/tests_for_package
283+
$ pip install pytest pytest-cov
284+
$ pytest --cov sklearn path/to/tests_for_package
285285

286286
see also :ref:`testing_coverage`
287287

@@ -519,21 +519,21 @@ Testing and improving test coverage
519519

520520
High-quality `unit testing <https://en.wikipedia.org/wiki/Unit_testing>`_
521521
is a corner-stone of the scikit-learn development process. For this
522-
purpose, we use the `nose <http://nose.readthedocs.io/en/latest/>`_
522+
purpose, we use the `pytest <https://docs.pytest.org>`_
523523
package. The tests are functions appropriately named, located in `tests`
524524
subdirectories, that check the validity of the algorithms and the
525525
different options of the code.
526526

527527
The full scikit-learn tests can be run using 'make' in the root folder.
528-
Alternatively, running 'nosetests' in a folder will run all the tests of
528+
Alternatively, running 'pytest' in a folder will run all the tests of
529529
the corresponding subpackages.
530530

531531
We expect code coverage of new features to be at least around 90%.
532532

533533
.. note:: **Workflow to improve test coverage**
534534

535535
To test code coverage, you need to install the `coverage
536-
<https://pypi.python.org/pypi/coverage>`_ package in addition to nose.
536+
<https://pypi.python.org/pypi/coverage>`_ package in addition to pytest.
537537

538538
1. Run 'make test-coverage'. The output lists for each file the line
539539
numbers that are not tested.

setup.cfg

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,9 @@
11
[aliases]
2-
# python2.7 has upgraded unittest and it is no longer compatible with some
3-
# of our tests, so we run all through nose
4-
test = nosetests
5-
6-
[nosetests]
7-
# nosetests skips test files with the executable bit by default
8-
# which can silently hide failing tests.
9-
# There are no executable scripts within the scikit-learn project
10-
# so let's turn the --exe flag on to avoid skipping tests by
11-
# mistake.
12-
exe = 1
13-
cover-html = 1
14-
cover-html-dir = coverage
15-
cover-package = sklearn
16-
17-
detailed-errors = 1
18-
with-doctest = 1
19-
doctest-tests = 1
20-
doctest-extension = rst
21-
doctest-fixtures = _fixture
22-
ignore-files=^setup\.py$
23-
#doctest-options = +ELLIPSIS,+NORMALIZE_WHITESPACE
2+
test = pytest
243

254
[tool:pytest]
26-
# disable-pytest-warnings should be removed once we drop nose and we
27-
# rewrite tests using yield with parametrize
5+
# disable-pytest-warnings should be removed once we rewrite tests
6+
# using yield with parametrize
287
addopts =
298
--doctest-modules
309
--disable-pytest-warnings

0 commit comments

Comments
 (0)
0