From 53d6e469adde6cb478a8e7d6129f4103a584d307 Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Mon, 17 Sep 2018 18:23:15 +0200 Subject: [PATCH 1/5] Migrate to pytest --- CONTRIBUTING.md | 10 +++++----- Makefile | 8 ++++---- appveyor.yml | 4 ++-- ci_scripts/create_doc.sh | 2 +- ci_scripts/install.sh | 2 +- ci_scripts/success.sh | 4 ++-- ci_scripts/test.sh | 11 ++++++----- doc/contributing.rst | 2 +- setup.py | 4 ++-- tox.ini | 2 +- 10 files changed, 25 insertions(+), 24 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2bd3bf2a1..d68e6034e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -74,14 +74,14 @@ following rules before you submit a pull request: [task list](https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments) in the PR description. -- All tests pass when running `nosetests`. On +- All tests pass when running `pytest`. On Unix-like systems, check with (from the toplevel source folder): ```bash - $ nosetests + $ pytest ``` - For Windows systems, execute the command from an Anaconda Prompt or add `nosetests` to PATH before executing the command. + For Windows systems, execute the command from an Anaconda Prompt or add `pytest` to PATH before executing the command. - Documentation and high-coverage tests are necessary for enhancements to be accepted. Bug-fixes or new features should be provided with @@ -101,8 +101,8 @@ tools: - Code with good unittest **coverage** (at least 80%), check with: ```bash - $ pip install nose coverage - $ nosetests --with-coverage path/to/tests_for_package + $ pip install pytest pytest-cov + $ pytest --cov=. path/to/tests_for_package ``` - No pyflakes warnings, check with: diff --git a/Makefile b/Makefile index 5f334667a..c36acbe9f 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ PYTHON ?= python CYTHON ?= cython -NOSETESTS ?= nosetests +PYTEST ?= pytest CTAGS ?= ctags all: clean inplace test @@ -16,12 +16,12 @@ inplace: $(PYTHON) setup.py build_ext -i test-code: in - $(NOSETESTS) -s -v tests + $(PYTEST) -s -v tests test-doc: - $(NOSETESTS) -s -v doc/*.rst + $(PYTEST) -s -v doc/*.rst test-coverage: rm -rf coverage .coverage - $(NOSETESTS) -s -v --with-coverage tests + $(PYTEST) -s -v --cov=. tests test: test-code test-sphinxext test-doc diff --git a/appveyor.yml b/appveyor.yml index 4b111df4b..6b12ceb7d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -37,7 +37,7 @@ install: # Install the build and runtime dependencies of the project. - "cd C:\\projects\\openml-python" - conda install --quiet --yes scikit-learn=0.18.2 - - conda install --quiet --yes mock numpy scipy nose requests nbformat python-dateutil nbconvert pandas matplotlib seaborn + - conda install --quiet --yes mock numpy scipy pytest requests nbformat python-dateutil nbconvert pandas matplotlib seaborn - pip install liac-arff xmltodict oslo.concurrency - "python setup.py install" #%CMD_IN_ENV% @@ -47,4 +47,4 @@ build: false test_script: - "cd C:\\projects\\openml-python" - - "%CMD_IN_ENV% python setup.py test" + - "%CMD_IN_ENV% pytest" diff --git a/ci_scripts/create_doc.sh b/ci_scripts/create_doc.sh index 3bcdbfe32..c9dd800a0 100644 --- a/ci_scripts/create_doc.sh +++ b/ci_scripts/create_doc.sh @@ -6,7 +6,7 @@ if ! [[ -z ${DOCPUSH+x} ]]; then if [[ "$DOCPUSH" == "true" ]]; then # install documentation building dependencies - pip install --upgrade matplotlib seaborn setuptools nose coverage sphinx pillow sphinx-gallery sphinx_bootstrap_theme cython numpydoc nbformat nbconvert + pip install matplotlib seaborn sphinx pillow sphinx-gallery sphinx_bootstrap_theme cython numpydoc nbformat nbconvert # $1 is the branch name # $2 is the global variable where we set the script status diff --git a/ci_scripts/install.sh b/ci_scripts/install.sh index 8f766f933..e4859f96a 100644 --- a/ci_scripts/install.sh +++ b/ci_scripts/install.sh @@ -26,7 +26,7 @@ popd # provided versions conda create -n testenv --yes python=$PYTHON_VERSION pip source activate testenv -pip install nose numpy scipy cython scikit-learn==$SKLEARN_VERSION \ +pip install pytest pytest-xdist pytest-timeout numpy scipy cython scikit-learn==$SKLEARN_VERSION \ oslo.concurrency if [[ "$EXAMPLES" == "true" ]]; then diff --git a/ci_scripts/success.sh b/ci_scripts/success.sh index be9fbb954..dbeb18e58 100644 --- a/ci_scripts/success.sh +++ b/ci_scripts/success.sh @@ -2,7 +2,7 @@ set -e if [[ "$COVERAGE" == "true" ]]; then # Need to run coveralls from a git checkout, so we copy .coverage - # from TEST_DIR where nosetests has been run + # from TEST_DIR where pytest has been run cp $TEST_DIR/.coverage $TRAVIS_BUILD_DIR cd $TRAVIS_BUILD_DIR # Ignore coveralls failures as the coveralls server is not @@ -10,4 +10,4 @@ if [[ "$COVERAGE" == "true" ]]; then # in the github UI just because the coverage report failed to # be published. codecov || echo "Codecov upload failed" -fi \ No newline at end of file +fi diff --git a/ci_scripts/test.sh b/ci_scripts/test.sh index 49f7d4f50..d574ac605 100644 --- a/ci_scripts/test.sh +++ b/ci_scripts/test.sh @@ -11,11 +11,12 @@ doctest_dir=$cwd/doc cd $TEST_DIR if [[ "$EXAMPLES" == "true" ]]; then - nosetests -sv $test_dir/test_examples/ + pytest -sv $test_dir/test_examples/ elif [[ "$DOCTEST" == "true" ]]; then python -m doctest $doctest_dir/usage.rst -elif [[ "$COVERAGE" == "true" ]]; then - nosetests --processes=4 --process-timeout=600 -sv --ignore-files="test_OpenMLDemo\.py" --with-coverage --cover-package=$MODULE $test_dir -else - nosetests --processes=4 --process-timeout=600 -sv --ignore-files="test_OpenMLDemo\.py" $test_dir +if [[ "$COVERAGE" == "true" ]]; then + PYTEST_ARGS="--cov=." +else; + PYTEST_ARGS="" fi +pytest -n 4 --timeout=600 --timeout-method=thread -sv --ignore='test_OpenMLDemo.py' $PYTEST_ARGS $test_dir diff --git a/doc/contributing.rst b/doc/contributing.rst index 3772e5eff..7b2a0fb3c 100644 --- a/doc/contributing.rst +++ b/doc/contributing.rst @@ -104,7 +104,7 @@ From within the directory of the cloned package, execute: .. code:: bash - nosetests tests/ + pytest tests/ .. _extending: diff --git a/setup.py b/setup.py index 13de76a36..827c354b8 100644 --- a/setup.py +++ b/setup.py @@ -39,7 +39,7 @@ 'scipy>=0.13.3', 'liac-arff>=2.2.2', 'xmltodict', - 'nose', + 'pytest', 'requests', 'scikit-learn>=0.18', 'nbformat', @@ -52,7 +52,7 @@ 'jupyter_client' ] }, - test_suite="nose.collector", + test_suite="pytest", classifiers=['Intended Audience :: Science/Research', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', diff --git a/tox.ini b/tox.ini index fbf6b6537..e7704e763 100755 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,7 @@ deps = scipy > 0.9 pandas > 0.13.1 xmltodict - nose + pytest mock commands= python setup.py install From 6533e88369987748632281bd92690f43c10e2f6b Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Tue, 18 Sep 2018 16:52:50 +0200 Subject: [PATCH 2/5] Fix typo in Travis CI and permission errors on Windows --- ci_scripts/test.sh | 9 ++++++--- openml/testing.py | 9 ++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ci_scripts/test.sh b/ci_scripts/test.sh index d574ac605..d20fbcfd8 100644 --- a/ci_scripts/test.sh +++ b/ci_scripts/test.sh @@ -14,9 +14,12 @@ if [[ "$EXAMPLES" == "true" ]]; then pytest -sv $test_dir/test_examples/ elif [[ "$DOCTEST" == "true" ]]; then python -m doctest $doctest_dir/usage.rst +fi + if [[ "$COVERAGE" == "true" ]]; then - PYTEST_ARGS="--cov=." -else; - PYTEST_ARGS="" + PYTEST_ARGS='--cov=.' +else + PYTEST_ARGS='' fi + pytest -n 4 --timeout=600 --timeout-method=thread -sv --ignore='test_OpenMLDemo.py' $PYTEST_ARGS $test_dir diff --git a/openml/testing.py b/openml/testing.py index b4aee20b5..ed63c6776 100644 --- a/openml/testing.py +++ b/openml/testing.py @@ -67,7 +67,14 @@ def setUp(self): def tearDown(self): os.chdir(self.cwd) - shutil.rmtree(self.workdir) + try: + shutil.rmtree(self.workdir) + except PermissionError: + if os.name == 'nt': + # one of the files may still be used by another process + pass + else: + raise openml.config.server = self.production_server def _add_sentinel_to_flow_name(self, flow, sentinel=None): From f1c50c480b0c17e6fd744738231e6f6d6e685254 Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Tue, 18 Sep 2018 17:54:13 +0200 Subject: [PATCH 3/5] Also install test dependencies --- appveyor.yml | 2 +- ci_scripts/install.sh | 2 +- setup.py | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 6b12ceb7d..0eeee921d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -39,7 +39,7 @@ install: - conda install --quiet --yes scikit-learn=0.18.2 - conda install --quiet --yes mock numpy scipy pytest requests nbformat python-dateutil nbconvert pandas matplotlib seaborn - pip install liac-arff xmltodict oslo.concurrency - - "python setup.py install" #%CMD_IN_ENV% + - "pip install .[test]" # Not a .NET project, we build scikit-learn in the install step instead diff --git a/ci_scripts/install.sh b/ci_scripts/install.sh index e4859f96a..abccadf45 100644 --- a/ci_scripts/install.sh +++ b/ci_scripts/install.sh @@ -43,4 +43,4 @@ fi python --version python -c "import numpy; print('numpy %s' % numpy.__version__)" python -c "import scipy; print('scipy %s' % scipy.__version__)" -python setup.py develop +pip install -e '.[test]' diff --git a/setup.py b/setup.py index 827c354b8..3c463b87b 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,8 @@ extras_require={ 'test': [ 'nbconvert', - 'jupyter_client' + 'jupyter_client', + 'matplotlib' ] }, test_suite="pytest", From 9edff6dbbcad6f7b21bab896e9cf6beb0d72108f Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Wed, 19 Sep 2018 11:24:29 +0200 Subject: [PATCH 4/5] Fix test coverage --- ci_scripts/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci_scripts/test.sh b/ci_scripts/test.sh index d20fbcfd8..ba18d7b63 100644 --- a/ci_scripts/test.sh +++ b/ci_scripts/test.sh @@ -17,7 +17,7 @@ elif [[ "$DOCTEST" == "true" ]]; then fi if [[ "$COVERAGE" == "true" ]]; then - PYTEST_ARGS='--cov=.' + PYTEST_ARGS='--cov=openml' else PYTEST_ARGS='' fi From 840df25225628101fa91d08bbc1452cabe4dfeb8 Mon Sep 17 00:00:00 2001 From: Roman Yurchak Date: Wed, 19 Sep 2018 14:10:57 +0200 Subject: [PATCH 5/5] Also add pytest-cov --- ci_scripts/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci_scripts/install.sh b/ci_scripts/install.sh index abccadf45..098650115 100644 --- a/ci_scripts/install.sh +++ b/ci_scripts/install.sh @@ -37,7 +37,7 @@ if [[ "$DOCTEST" == "true" ]]; then pip install pandas sphinx_bootstrap_theme fi if [[ "$COVERAGE" == "true" ]]; then - pip install codecov + pip install codecov pytest-cov fi python --version