-
-
Notifications
You must be signed in to change notification settings - Fork 25.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MRG+1] Remove nose from CIs and documentation #9840
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,17 +4,12 @@ | |
|
||
PYTHON ?= python | ||
CYTHON ?= cython | ||
NOSETESTS ?= nosetests | ||
PYTEST ?= pytest | ||
CTAGS ?= ctags | ||
|
||
# skip doctests on 32bit python | ||
BITS := $(shell python -c 'import struct; print(8 * struct.calcsize("P"))') | ||
|
||
ifeq ($(BITS),32) | ||
NOSETESTS:=$(NOSETESTS) -c setup32.cfg | ||
endif | ||
|
||
|
||
all: clean inplace test | ||
|
||
clean-ctags: | ||
|
@@ -29,19 +24,17 @@ inplace: | |
$(PYTHON) setup.py build_ext -i | ||
|
||
test-code: in | ||
$(NOSETESTS) -s -v sklearn | ||
$(PYTEST) --showlocals -v sklearn | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this doesn't show warnings, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what you mean:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't able to turn on all the warnings we get with nosetests, and I think that's a bad thing. For example I couldn't get deprecation warnings (ours or numpy) to show. But I'm new to pytest There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From https://docs.pytest.org/en/latest/warnings.html:
and
What I was not fully aware of this but it seems that Reading more carefully https://docs.pytest.org/en/latest/warnings.html, it looks like you can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking closely at it, removing
Side comment: actually we get less than 100 "yield tests are deprecated, and scheduled to be removed in pytest 4.0" warnings. So the original motivation for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should make sure we don't use warnings instead of ignoring them. Many of them are important. Hiding them hides the problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the output of nose, I see that many of those are pretty recently introduced and probably point to real issues.... |
||
test-sphinxext: | ||
$(NOSETESTS) -s -v doc/sphinxext/ | ||
$(PYTEST) --showlocals -v doc/sphinxext/ | ||
test-doc: | ||
ifeq ($(BITS),64) | ||
$(NOSETESTS) -s -v doc/*.rst doc/modules/ doc/datasets/ \ | ||
doc/developers doc/tutorial/basic doc/tutorial/statistical_inference \ | ||
doc/tutorial/text_analytics | ||
$(PYTEST) $(shell find doc -name '*.rst' | sort) | ||
endif | ||
|
||
test-coverage: | ||
rm -rf coverage .coverage | ||
$(NOSETESTS) -s -v --with-coverage sklearn | ||
$(PYTEST) sklearn --show-locals -v --with-cov sklearn | ||
|
||
test: test-code test-sphinxext test-doc | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,15 +110,9 @@ Testing | |
~~~~~~~ | ||
|
||
After installation, you can launch the test suite from outside the | ||
source directory (you will need to have the ``nose`` package installed):: | ||
source directory (you will need to have the ``pytest`` package installed):: | ||
|
||
nosetests -v sklearn | ||
|
||
Under Windows, it is recommended to use the following command (adjust the path | ||
to the ``python.exe`` program) as using the ``nosetests.exe`` program can badly | ||
interact with tests that use ``multiprocessing``:: | ||
|
||
C:\Python34\python.exe -c "import nose; nose.main()" -v sklearn | ||
pytest sklearn | ||
|
||
See the web page http://scikit-learn.org/stable/developers/advanced_installation.html#testing | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better to change the web page to dev version? I am instructed to use pytest and I want to click in the link for more information, but are soon surrounded by nose :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch I guess this would make a lot of sense in this case. Feel free to do a quick grep to spot similar problems with the nose to pytest move and open a PR. |
||
for more information. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
numpy==1.9.3 | ||
scipy==0.16.0 | ||
cython | ||
nose | ||
nose-timer | ||
pytest | ||
wheel | ||
wheelhouse_uploader |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,15 +21,12 @@ except ImportError: | |
python -c "import multiprocessing as mp; print('%d CPUs' % mp.cpu_count())" | ||
|
||
run_tests() { | ||
if [[ "$USE_PYTEST" == "true" ]]; then | ||
TEST_CMD="pytest --showlocals --durations=20 --pyargs" | ||
else | ||
TEST_CMD="nosetests --with-timer --timer-top-n 20" | ||
fi | ||
TEST_CMD="pytest --showlocals --durations=20 --pyargs" | ||
|
||
# Get into a temp directory to run test from the installed scikit-learn and | ||
# check if we do not leave artifacts | ||
mkdir -p $TEST_DIR | ||
# We need the setup.cfg for the nose settings | ||
# We need the setup.cfg for the pytest settings | ||
cp setup.cfg $TEST_DIR | ||
cd $TEST_DIR | ||
|
||
|
@@ -39,23 +36,18 @@ run_tests() { | |
export SKLEARN_SKIP_NETWORK_TESTS=1 | ||
|
||
if [[ "$COVERAGE" == "true" ]]; then | ||
TEST_CMD="$TEST_CMD --with-coverage" | ||
TEST_CMD="$TEST_CMD --cov sklearn" | ||
fi | ||
$TEST_CMD sklearn | ||
|
||
# Going back to git checkout folder needed to test documentation | ||
cd $OLDPWD | ||
|
||
if [[ "$USE_PYTEST" == "true" ]]; then | ||
# Do not run doctests in scipy-dev-wheels build for now | ||
# (broken by numpy 1.14.dev array repr/str formatting | ||
# change even with np.set_printoptions(sign='legacy')). | ||
# See https://github.com/numpy/numpy/issues/9804 for more details | ||
if [[ "$DISTRIB" != "scipy-dev-wheels" ]]; then | ||
pytest $(find doc -name '*.rst' | sort) | ||
fi | ||
else | ||
# Makefile is using nose | ||
# Do not run doctests in scipy-dev-wheels build for now | ||
# (broken by numpy 1.14.dev array repr/str formatting | ||
# change even with np.set_printoptions(sign='legacy')). | ||
# See https://github.com/numpy/numpy/issues/9804 for more details | ||
if [[ "$DISTRIB" != "scipy-dev-wheels" ]]; then | ||
make test-doc | ||
fi | ||
} | ||
|
@@ -67,3 +59,18 @@ fi | |
if [[ "$SKIP_TESTS" != "true" ]]; then | ||
run_tests | ||
fi | ||
|
||
if [[ "$CHECK_PYTEST_SOFT_DEPENDENCY" == "true" ]]; then | ||
conda remove -y py pytest || pip uninstall -y py pytest | ||
if [[ "$COVERAGE" == "true" ]]; then | ||
# Need to append the coverage to the existing .coverage generated by | ||
# running the tests | ||
CMD="coverage run --append" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what the point of this is. The union of the coverage of running the tests with pytest and running the estimator checks without pytest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes. This way you can see that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, fine by me. I'm good with merging either way. |
||
else | ||
CMD="python" | ||
fi | ||
# .coverage from running the tests is in TEST_DIR | ||
cd $TEST_DIR | ||
$CMD -m sklearn.utils.tests.test_estimator_checks | ||
cd $OLDPWD | ||
fi |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -376,24 +376,17 @@ Testing | |
Testing scikit-learn once installed | ||
----------------------------------- | ||
|
||
Testing requires having the `nose | ||
<https://nose.readthedocs.io/en/latest/>`_ library. After | ||
Testing requires having the `pytest | ||
<https://docs.pytest.org>`_ library. After | ||
installation, the package can be tested by executing *from outside* the | ||
source directory:: | ||
|
||
$ nosetests -v sklearn | ||
|
||
Under Windows, it is recommended to use the following command (adjust the path | ||
to the ``python.exe`` program) as using the ``nosetests.exe`` program can badly | ||
interact with tests that use ``multiprocessing``:: | ||
|
||
C:\Python34\python.exe -c "import nose; nose.main()" -v sklearn | ||
$ pytest sklearn | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure what the recommendation should be. I rarely use -v myself and I would argue that it is only useful (if at all) if you only have a log file e.g. on our CIs, to make sure that a particular test was run or succeeded or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your point. Personally, I frequently use |
||
|
||
This should give you a lot of output (and some warnings) but | ||
eventually should finish with a message similar to:: | ||
|
||
Ran 3246 tests in 260.618s | ||
OK (SKIP=20) | ||
=========== 8304 passed, 26 skipped, 4659 warnings in 557.76 seconds =========== | ||
|
||
Otherwise, please consider posting an issue into the `bug tracker | ||
<https://github.com/scikit-learn/scikit-learn/issues>`_ or to the | ||
|
@@ -411,9 +404,9 @@ source directory:: | |
|
||
python setup.py build_ext --inplace | ||
|
||
Test can now be run using nosetests:: | ||
Test can now be run using pytest:: | ||
|
||
nosetests -v sklearn/ | ||
pytest sklearn | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above |
||
|
||
This is automated by the commands:: | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -280,8 +280,8 @@ You can also check for common programming errors with the following tools: | |
* Code with a good unittest coverage (at least 90%, better 100%), check | ||
with:: | ||
|
||
$ pip install nose coverage | ||
$ nosetests --with-coverage path/to/tests_for_package | ||
$ pip install pytest pytest-cov | ||
$ pytest --cov sklearn path/to/tests_for_package | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add an example to test a single test?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather try to keep this PR minimal, essentially the doc should only be a nose -> pytest translation. |
||
|
||
see also :ref:`testing_coverage` | ||
|
||
|
@@ -519,21 +519,21 @@ Testing and improving test coverage | |
|
||
High-quality `unit testing <https://en.wikipedia.org/wiki/Unit_testing>`_ | ||
is a corner-stone of the scikit-learn development process. For this | ||
purpose, we use the `nose <http://nose.readthedocs.io/en/latest/>`_ | ||
purpose, we use the `pytest <https://docs.pytest.org>`_ | ||
package. The tests are functions appropriately named, located in `tests` | ||
subdirectories, that check the validity of the algorithms and the | ||
different options of the code. | ||
|
||
The full scikit-learn tests can be run using 'make' in the root folder. | ||
Alternatively, running 'nosetests' in a folder will run all the tests of | ||
Alternatively, running 'pytest' in a folder will run all the tests of | ||
the corresponding subpackages. | ||
|
||
We expect code coverage of new features to be at least around 90%. | ||
|
||
.. note:: **Workflow to improve test coverage** | ||
|
||
To test code coverage, you need to install the `coverage | ||
<https://pypi.python.org/pypi/coverage>`_ package in addition to nose. | ||
<https://pypi.python.org/pypi/coverage>`_ package in addition to pytest. | ||
|
||
1. Run 'make test-coverage'. The output lists for each file the line | ||
numbers that are not tested. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also put this in its own worker to be sure it's sandboxed, but I guess it's okay as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about too but I thought this is a bit of a waste to have another build and run tests only for 5 seconds.