Skip to content

TST: Use pytest #13856

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

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ dist
**/wheelhouse/*
# coverage
.coverage
coverage.xml
coverage_html_report

# OS generated files #
######################
Expand Down
38 changes: 19 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ matrix:
env:
- PYTHON_VERSION=3.5
- JOB_NAME: "35_osx"
- NOSE_ARGS="not slow and not network and not disabled"
- TEST_ARGS="--skip-slow --skip-network"
- BUILD_TYPE=conda
- JOB_TAG=_OSX
- TRAVIS_PYTHON_VERSION=3.5
Expand All @@ -42,7 +42,7 @@ matrix:
env:
- PYTHON_VERSION=2.7
- JOB_NAME: "27_slow_nnet_LOCALE"
- NOSE_ARGS="slow and not network and not disabled"
- TEST_ARGS="--only-slow --skip-network"
- LOCALE_OVERRIDE="zh_CN.UTF-8"
- FULL_DEPS=true
- JOB_TAG=_LOCALE
Expand All @@ -56,7 +56,7 @@ matrix:
env:
- PYTHON_VERSION=2.7
- JOB_NAME: "27_nslow"
- NOSE_ARGS="not slow and not disabled"
- TEST_ARGS="--skip-slow"
- FULL_DEPS=true
- CLIPBOARD_GUI=gtk2
- LINT=true
Expand All @@ -70,7 +70,7 @@ matrix:
env:
- PYTHON_VERSION=3.5
- JOB_NAME: "35_nslow"
- NOSE_ARGS="not slow and not network and not disabled"
- TEST_ARGS="--skip-slow --skip-network"
- FULL_DEPS=true
- CLIPBOARD=xsel
- COVERAGE=true
Expand All @@ -84,7 +84,7 @@ matrix:
env:
- PYTHON_VERSION=3.6
- JOB_NAME: "36"
- NOSE_ARGS="not slow and not network and not disabled"
- TEST_ARGS="--skip-slow --skip-network"
- PANDAS_TESTING_MODE="deprecate"
addons:
apt:
Expand All @@ -96,7 +96,7 @@ matrix:
env:
- PYTHON_VERSION=2.7
- JOB_NAME: "27_nslow_nnet_COMPAT"
- NOSE_ARGS="not slow and not network and not disabled"
- TEST_ARGS="--skip-slow --skip-network"
- LOCALE_OVERRIDE="it_IT.UTF-8"
- INSTALL_TEST=true
- JOB_TAG=_COMPAT
Expand All @@ -112,7 +112,7 @@ matrix:
- PYTHON_VERSION=2.7
- JOB_NAME: "27_slow"
- JOB_TAG=_SLOW
- NOSE_ARGS="slow and not network and not disabled"
- TEST_ARGS="--only-slow --skip-network"
- FULL_DEPS=true
- CACHE_NAME="27_slow"
- USE_CACHE=true
Expand All @@ -122,7 +122,7 @@ matrix:
- PYTHON_VERSION=2.7
- JOB_NAME: "27_build_test_conda"
- JOB_TAG=_BUILD_TEST
- NOSE_ARGS="not slow and not disabled"
- TEST_ARGS="--skip-slow"
- FULL_DEPS=true
- BUILD_TEST=true
- CACHE_NAME="27_build_test_conda"
Expand All @@ -133,7 +133,7 @@ matrix:
- PYTHON_VERSION=3.4
- JOB_NAME: "34_nslow"
- LOCALE_OVERRIDE="zh_CN.UTF-8"
- NOSE_ARGS="not slow and not disabled"
- TEST_ARGS="--skip-slow"
- FULL_DEPS=true
- CLIPBOARD=xsel
- CACHE_NAME="34_nslow"
Expand All @@ -149,7 +149,7 @@ matrix:
- PYTHON_VERSION=3.4
- JOB_NAME: "34_slow"
- JOB_TAG=_SLOW
- NOSE_ARGS="slow and not network and not disabled"
- TEST_ARGS="--only-slow --skip-network"
- FULL_DEPS=true
- CLIPBOARD=xsel
- CACHE_NAME="34_slow"
Expand All @@ -164,7 +164,7 @@ matrix:
- PYTHON_VERSION=3.5
- JOB_NAME: "35_numpy_dev"
- JOB_TAG=_NUMPY_DEV
- NOSE_ARGS="not slow and not network and not disabled"
- TEST_ARGS="--skip-slow --skip-network"
- PANDAS_TESTING_MODE="deprecate"
- CACHE_NAME="35_numpy_dev"
- USE_CACHE=true
Expand All @@ -179,7 +179,7 @@ matrix:
- PYTHON_VERSION=3.5
- JOB_NAME: "35_ascii"
- JOB_TAG=_ASCII
- NOSE_ARGS="not slow and not network and not disabled"
- TEST_ARGS="--skip-slow --skip-network"
- LOCALE_OVERRIDE="C"
- CACHE_NAME="35_ascii"
- USE_CACHE=true
Expand All @@ -199,7 +199,7 @@ matrix:
- PYTHON_VERSION=2.7
- JOB_NAME: "27_slow"
- JOB_TAG=_SLOW
- NOSE_ARGS="slow and not network and not disabled"
- TEST_ARGS="--only-slow --skip-network"
- FULL_DEPS=true
- CACHE_NAME="27_slow"
- USE_CACHE=true
Expand All @@ -208,7 +208,7 @@ matrix:
- PYTHON_VERSION=3.4
- JOB_NAME: "34_slow"
- JOB_TAG=_SLOW
- NOSE_ARGS="slow and not network and not disabled"
- TEST_ARGS="--only-slow --skip-network"
- FULL_DEPS=true
- CLIPBOARD=xsel
- CACHE_NAME="34_slow"
Expand All @@ -222,7 +222,7 @@ matrix:
- PYTHON_VERSION=2.7
- JOB_NAME: "27_build_test_conda"
- JOB_TAG=_BUILD_TEST
- NOSE_ARGS="not slow and not disabled"
- TEST_ARGS="--skip-slow"
- FULL_DEPS=true
- BUILD_TEST=true
- CACHE_NAME="27_build_test_conda"
Expand All @@ -232,7 +232,7 @@ matrix:
- PYTHON_VERSION=3.4
- JOB_NAME: "34_nslow"
- LOCALE_OVERRIDE="zh_CN.UTF-8"
- NOSE_ARGS="not slow and not disabled"
- TEST_ARGS="--skip-slow"
- FULL_DEPS=true
- CLIPBOARD=xsel
- CACHE_NAME="34_nslow"
Expand All @@ -247,7 +247,7 @@ matrix:
- PYTHON_VERSION=3.5
- JOB_NAME: "35_numpy_dev"
- JOB_TAG=_NUMPY_DEV
- NOSE_ARGS="not slow and not network and not disabled"
- TEST_ARGS="--skip-slow --skip-network"
- PANDAS_TESTING_MODE="deprecate"
- CACHE_NAME="35_numpy_dev"
- USE_CACHE=true
Expand All @@ -260,7 +260,7 @@ matrix:
env:
- PYTHON_VERSION=2.7
- JOB_NAME: "27_nslow_nnet_COMPAT"
- NOSE_ARGS="not slow and not network and not disabled"
- TEST_ARGS="--skip-slow --skip-network"
- LOCALE_OVERRIDE="it_IT.UTF-8"
- INSTALL_TEST=true
- JOB_TAG=_COMPAT
Expand All @@ -275,7 +275,7 @@ matrix:
- PYTHON_VERSION=3.5
- JOB_NAME: "35_ascii"
- JOB_TAG=_ASCII
- NOSE_ARGS="not slow and not network and not disabled"
- TEST_ARGS="--skip-slow --skip-network"
- LOCALE_OVERRIDE="C"
- CACHE_NAME="35_ascii"
- USE_CACHE=true
Expand Down
8 changes: 5 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ environment:
# /E:ON and /V:ON options are not enabled in the batch script intepreter
# See: http://stackoverflow.com/a/13751649/163740
CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\ci\\run_with_env.cmd"
clone_folder: C:\projects\pandas

matrix:

Expand Down Expand Up @@ -82,7 +83,7 @@ install:
- cmd: '%CMD_IN_ENV% conda build ci\appveyor.recipe -q'

# create our env
- cmd: conda create -q -n pandas python=%PYTHON_VERSION% nose
- cmd: conda create -q -n pandas python=%PYTHON_VERSION% nose pytest
- cmd: activate pandas
- SET REQ=ci\requirements-%PYTHON_VERSION%-%PYTHON_ARCH%.run
- cmd: echo "installing requirements from %REQ%"
Expand All @@ -93,7 +94,8 @@ install:

test_script:
# tests
- cd \
- cmd: activate pandas
- cmd: conda list
- cmd: nosetests --exe -A "not slow and not network and not disabled" pandas
- cmd: cd \
- cmd: python -c "import pandas; pandas.test(['--skip-slow', '--skip-network'])"

3 changes: 2 additions & 1 deletion ci/install_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ if [ "$INSTALL_TEST" ]; then
conda uninstall cython || exit 1
python "$TRAVIS_BUILD_DIR"/setup.py sdist --formats=zip,gztar || exit 1
pip install "$TRAVIS_BUILD_DIR"/dist/*tar.gz || exit 1
nosetests --exe -A "$NOSE_ARGS" pandas/tests/test_series.py --with-xunit --xunit-file=/tmp/nosetests_install.xml
# nosetests --exe -A "$TEST_ARGS" pandas/tests/test_series.py --with-xunit --xunit-file=/tmp/nosetests_install.xml
pytest pandas/tests/test_series.py --junitxml=/tmp/pytest_install.xml
else
echo "Skipping installation test."
fi
Expand Down
11 changes: 6 additions & 5 deletions ci/install_travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,17 @@ else

# Useful for debugging any issues with conda
conda info -a || exit 1

fi

# may have installation instructions for this build
INSTALL="ci/install-${PYTHON_VERSION}${JOB_TAG}.sh"
if [ -e ${INSTALL} ]; then
time bash $INSTALL || exit 1
else

# create new env
time conda create -n pandas python=$PYTHON_VERSION nose || exit 1
time conda create -n pandas python=$PYTHON_VERSION nose pytest || exit 1

if [ "$COVERAGE" ]; then
pip install coverage
fi
if [ "$LINT" ]; then
conda install flake8
pip install cpplint
Expand All @@ -119,6 +116,10 @@ fi

source activate pandas

if [ "$COVERAGE" ]; then
pip install coverage pytest-cov
fi

if [ "$BUILD_TEST" ]; then

# build testing
Expand Down
2 changes: 2 additions & 0 deletions ci/requirements_all.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
nose
pytest
pytest-cov
flake8
sphinx
ipython
Expand Down
2 changes: 2 additions & 0 deletions ci/requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ pytz
numpy
cython
nose
pytest
pytest-cov
flake8
8 changes: 4 additions & 4 deletions ci/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ fi
if [ "$BUILD_TEST" ]; then
echo "We are not running nosetests as this is simply a build test."
elif [ "$COVERAGE" ]; then
echo nosetests --exe -A "$NOSE_ARGS" pandas --with-coverage --with-xunit --xunit-file=/tmp/nosetests.xml
nosetests --exe -A "$NOSE_ARGS" pandas --with-coverage --cover-package=pandas --cover-tests --with-xunit --xunit-file=/tmp/nosetests.xml
echo pytest -s --cov=pandas --cov-report xml:/tmp/nosetests.xml $TEST_ARGS pandas
pytest -s --cov=pandas --cov-report xml:/tmp/nosetests.xml $TEST_ARGS pandas
else
echo nosetests --exe -A "$NOSE_ARGS" pandas --doctest-tests --with-xunit --xunit-file=/tmp/nosetests.xml
nosetests --exe -A "$NOSE_ARGS" pandas --doctest-tests --with-xunit --xunit-file=/tmp/nosetests.xml
echo pytest $TEST_ARGS pandas
pytest $TEST_ARGS pandas # TODO: doctest
fi

RET="$?"
Expand Down
24 changes: 16 additions & 8 deletions doc/source/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ use cases and writing corresponding tests.
Adding tests is one of the most common requests after code is pushed to *pandas*. Therefore,
it is worth getting in the habit of writing tests ahead of time so this is never an issue.

Like many packages, *pandas* uses the `Nose testing system
<https://nose.readthedocs.io/en/latest/index.html>`_ and the convenient
Like many packages, *pandas* uses `pytest
<http://doc.pytest.org/en/latest/>`_ and the convenient
extensions in `numpy.testing
<http://docs.scipy.org/doc/numpy/reference/routines.testing.html>`_.

Expand Down Expand Up @@ -595,17 +595,25 @@ Running the test suite
The tests can then be run directly inside your Git clone (without having to
install *pandas*) by typing::

nosetests pandas
pytest pandas

The tests suite is exhaustive and takes around 20 minutes to run. Often it is
worth running only a subset of tests first around your changes before running the
entire suite. This is done using one of the following constructs::
entire suite.

nosetests pandas/tests/[test-module].py
nosetests pandas/tests/[test-module].py:[TestClass]
nosetests pandas/tests/[test-module].py:[TestClass].[test_method]
The easiest way to do this is with::

.. versionadded:: 0.18.0
pytest pandas/path/to/test.py -k regex_matching_test_name

Or with one of the following constructs::

pytest pandas/tests/[test-module].py
pytest pandas/tests/[test-module].py::[TestClass]
pytest pandas/tests/[test-module].py::[TestClass]::[test_method]

For more, see the `pytest<http://doc.pytest.org/en/latest/>`_ documentation.

.. versionadded:: 0.18.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prob should take out this tag


Furthermore one can run

Expand Down
4 changes: 2 additions & 2 deletions doc/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ Running the test suite
pandas is equipped with an exhaustive set of unit tests covering about 97% of
the codebase as of this writing. To run it on your machine to verify that
everything is working (and you have all of the dependencies, soft and hard,
installed), make sure you have `nose
<https://nose.readthedocs.io/en/latest/>`__ and run:
installed), make sure you have `pytest
<http://doc.pytest.org/en/latest/>`__ and run:

::

Expand Down
3 changes: 3 additions & 0 deletions doc/source/whatsnew/v0.20.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ Highlights include:

- Building pandas for development now requires ``cython >= 0.23`` (:issue:`14831`)
- The ``.ix`` indexer has been deprecated, see :ref:`here <whatsnew_0200.api_breaking.deprecate_ix>`
- Switched the test framework to `pytest`_ (:issue:`13097`)

.. _pytest: http://doc.pytest.org/en/latest/

Check the :ref:`API Changes <whatsnew_0200.api_breaking>` and :ref:`deprecations <whatsnew_0200.deprecations>` before updating.

Expand Down
6 changes: 1 addition & 5 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@

from pandas.io.api import *

# define the testing framework
import pandas.util.testing
from pandas.util.nosetester import NoseTester
test = NoseTester().test
del NoseTester
from pandas.util._tester import test

# use the closest tagged version if possible
from ._version import get_versions
Expand Down
2 changes: 1 addition & 1 deletion pandas/api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TestPDApi(Base, tm.TestCase):

# these are optionally imported based on testing
# & need to be ignored
ignored = ['tests', 'locale']
ignored = ['tests', 'locale', 'conftest']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to take this out


# top-level sub-packages
lib = ['api', 'compat', 'computation', 'core',
Expand Down
21 changes: 21 additions & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest


def pytest_addoption(parser):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should for sure be in the top-level and not here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like where it's at now either, but I think it's necessary. As this note says:

This function [pytest_addoption] should be implemented only in plugins or conftest.py files situated at the tests root directory due to how pytest discovers plugins during startup.

The other option, I suppose is to bundle a setuptools entrypoint so that our custom options show up for anyone who has pytest and pandas. We could prefix our --run-slow, etc with --pandas-run-slow, to avoid name clashes.

Do you have a preference between the two?

parser.addoption("--skip-slow", action="store_true",
help="skip slow tests")
parser.addoption("--skip-network", action="store_true",
help="run network tests")
parser.addoption("--only-slow", action="store_true",
help="run only slow tests")


def pytest_runtest_setup(item):
if 'slow' in item.keywords and item.config.getoption("--skip-slow"):
pytest.skip("skipping due to --skip-slow")

if 'slow' not in item.keywords and item.config.getoption("--only-slow"):
pytest.skip("skipping due to --only-slow")

if 'skip' in item.keywords and item.config.getoption("--skip-network"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the todo list, let's just make @network an actual marker then this becomes trival

pytest.skip("skipping due to --skip-network")
2 changes: 1 addition & 1 deletion pandas/io/tests/parser/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TestCompressedUrl(object):
'xz': '.xz',
}

def __init__(self):
def setup(self):
path = os.path.join(tm.get_data_path(), 'salaries.csv')
self.local_table = read_table(path)
self.base_url = ('https://github.com/pandas-dev/pandas/raw/master/'
Expand Down
Loading