Skip to content

Commit ab8822a

Browse files
TomAugspurgerjreback
authored andcommitted
TST: Use pytest
closes pandas-dev#13097 Author: Tom Augspurger <[email protected]> Closes pandas-dev#13856 from TomAugspurger/pytest and squashes the following commits: 59e2be9 [Tom Augspurger] NOSE_ARGS -> TEST_ARGS 03695aa [Tom Augspurger] TST: Remove disabled marks 42790ae [Tom Augspurger] TST: Remove test_multi.sh 40d7336 [Tom Augspurger] PKG: redo pd.test import 9ba1f12 [Tom Augspurger] TST: Skip if getlocale is None 14c447c [Tom Augspurger] TST: pd.test uses pytest c4f6008 [Tom Augspurger] TST/CI: Use pytest b268d89 [Tom Augspurger] TST: Change method to make reporting more standard a638390 [Tom Augspurger] TST: Test consistency change c8dc927 [Tom Augspurger] TST: Refactor to use setup_class 9b5f2b2 [Tom Augspurger] TST: Refactor sql test inheritance
1 parent e884072 commit ab8822a

31 files changed

+179
-373
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ dist
5656
**/wheelhouse/*
5757
# coverage
5858
.coverage
59+
coverage.xml
60+
coverage_html_report
5961

6062
# OS generated files #
6163
######################

Diff for: .travis.yml

+19-19
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ matrix:
3232
env:
3333
- PYTHON_VERSION=3.5
3434
- JOB_NAME: "35_osx"
35-
- NOSE_ARGS="not slow and not network and not disabled"
35+
- TEST_ARGS="--skip-slow --skip-network"
3636
- BUILD_TYPE=conda
3737
- JOB_TAG=_OSX
3838
- TRAVIS_PYTHON_VERSION=3.5
@@ -42,7 +42,7 @@ matrix:
4242
env:
4343
- PYTHON_VERSION=2.7
4444
- JOB_NAME: "27_slow_nnet_LOCALE"
45-
- NOSE_ARGS="slow and not network and not disabled"
45+
- TEST_ARGS="--only-slow --skip-network"
4646
- LOCALE_OVERRIDE="zh_CN.UTF-8"
4747
- FULL_DEPS=true
4848
- JOB_TAG=_LOCALE
@@ -56,7 +56,7 @@ matrix:
5656
env:
5757
- PYTHON_VERSION=2.7
5858
- JOB_NAME: "27_nslow"
59-
- NOSE_ARGS="not slow and not disabled"
59+
- TEST_ARGS="--skip-slow"
6060
- FULL_DEPS=true
6161
- CLIPBOARD_GUI=gtk2
6262
- LINT=true
@@ -70,7 +70,7 @@ matrix:
7070
env:
7171
- PYTHON_VERSION=3.5
7272
- JOB_NAME: "35_nslow"
73-
- NOSE_ARGS="not slow and not network and not disabled"
73+
- TEST_ARGS="--skip-slow --skip-network"
7474
- FULL_DEPS=true
7575
- CLIPBOARD=xsel
7676
- COVERAGE=true
@@ -84,7 +84,7 @@ matrix:
8484
env:
8585
- PYTHON_VERSION=3.6
8686
- JOB_NAME: "36"
87-
- NOSE_ARGS="not slow and not network and not disabled"
87+
- TEST_ARGS="--skip-slow --skip-network"
8888
- PANDAS_TESTING_MODE="deprecate"
8989
addons:
9090
apt:
@@ -96,7 +96,7 @@ matrix:
9696
env:
9797
- PYTHON_VERSION=2.7
9898
- JOB_NAME: "27_nslow_nnet_COMPAT"
99-
- NOSE_ARGS="not slow and not network and not disabled"
99+
- TEST_ARGS="--skip-slow --skip-network"
100100
- LOCALE_OVERRIDE="it_IT.UTF-8"
101101
- INSTALL_TEST=true
102102
- JOB_TAG=_COMPAT
@@ -112,7 +112,7 @@ matrix:
112112
- PYTHON_VERSION=2.7
113113
- JOB_NAME: "27_slow"
114114
- JOB_TAG=_SLOW
115-
- NOSE_ARGS="slow and not network and not disabled"
115+
- TEST_ARGS="--only-slow --skip-network"
116116
- FULL_DEPS=true
117117
- CACHE_NAME="27_slow"
118118
- USE_CACHE=true
@@ -122,7 +122,7 @@ matrix:
122122
- PYTHON_VERSION=2.7
123123
- JOB_NAME: "27_build_test_conda"
124124
- JOB_TAG=_BUILD_TEST
125-
- NOSE_ARGS="not slow and not disabled"
125+
- TEST_ARGS="--skip-slow"
126126
- FULL_DEPS=true
127127
- BUILD_TEST=true
128128
- CACHE_NAME="27_build_test_conda"
@@ -133,7 +133,7 @@ matrix:
133133
- PYTHON_VERSION=3.4
134134
- JOB_NAME: "34_nslow"
135135
- LOCALE_OVERRIDE="zh_CN.UTF-8"
136-
- NOSE_ARGS="not slow and not disabled"
136+
- TEST_ARGS="--skip-slow"
137137
- FULL_DEPS=true
138138
- CLIPBOARD=xsel
139139
- CACHE_NAME="34_nslow"
@@ -149,7 +149,7 @@ matrix:
149149
- PYTHON_VERSION=3.4
150150
- JOB_NAME: "34_slow"
151151
- JOB_TAG=_SLOW
152-
- NOSE_ARGS="slow and not network and not disabled"
152+
- TEST_ARGS="--only-slow --skip-network"
153153
- FULL_DEPS=true
154154
- CLIPBOARD=xsel
155155
- CACHE_NAME="34_slow"
@@ -164,7 +164,7 @@ matrix:
164164
- PYTHON_VERSION=3.5
165165
- JOB_NAME: "35_numpy_dev"
166166
- JOB_TAG=_NUMPY_DEV
167-
- NOSE_ARGS="not slow and not network and not disabled"
167+
- TEST_ARGS="--skip-slow --skip-network"
168168
- PANDAS_TESTING_MODE="deprecate"
169169
- CACHE_NAME="35_numpy_dev"
170170
- USE_CACHE=true
@@ -179,7 +179,7 @@ matrix:
179179
- PYTHON_VERSION=3.5
180180
- JOB_NAME: "35_ascii"
181181
- JOB_TAG=_ASCII
182-
- NOSE_ARGS="not slow and not network and not disabled"
182+
- TEST_ARGS="--skip-slow --skip-network"
183183
- LOCALE_OVERRIDE="C"
184184
- CACHE_NAME="35_ascii"
185185
- USE_CACHE=true
@@ -199,7 +199,7 @@ matrix:
199199
- PYTHON_VERSION=2.7
200200
- JOB_NAME: "27_slow"
201201
- JOB_TAG=_SLOW
202-
- NOSE_ARGS="slow and not network and not disabled"
202+
- TEST_ARGS="--only-slow --skip-network"
203203
- FULL_DEPS=true
204204
- CACHE_NAME="27_slow"
205205
- USE_CACHE=true
@@ -208,7 +208,7 @@ matrix:
208208
- PYTHON_VERSION=3.4
209209
- JOB_NAME: "34_slow"
210210
- JOB_TAG=_SLOW
211-
- NOSE_ARGS="slow and not network and not disabled"
211+
- TEST_ARGS="--only-slow --skip-network"
212212
- FULL_DEPS=true
213213
- CLIPBOARD=xsel
214214
- CACHE_NAME="34_slow"
@@ -222,7 +222,7 @@ matrix:
222222
- PYTHON_VERSION=2.7
223223
- JOB_NAME: "27_build_test_conda"
224224
- JOB_TAG=_BUILD_TEST
225-
- NOSE_ARGS="not slow and not disabled"
225+
- TEST_ARGS="--skip-slow"
226226
- FULL_DEPS=true
227227
- BUILD_TEST=true
228228
- CACHE_NAME="27_build_test_conda"
@@ -232,7 +232,7 @@ matrix:
232232
- PYTHON_VERSION=3.4
233233
- JOB_NAME: "34_nslow"
234234
- LOCALE_OVERRIDE="zh_CN.UTF-8"
235-
- NOSE_ARGS="not slow and not disabled"
235+
- TEST_ARGS="--skip-slow"
236236
- FULL_DEPS=true
237237
- CLIPBOARD=xsel
238238
- CACHE_NAME="34_nslow"
@@ -247,7 +247,7 @@ matrix:
247247
- PYTHON_VERSION=3.5
248248
- JOB_NAME: "35_numpy_dev"
249249
- JOB_TAG=_NUMPY_DEV
250-
- NOSE_ARGS="not slow and not network and not disabled"
250+
- TEST_ARGS="--skip-slow --skip-network"
251251
- PANDAS_TESTING_MODE="deprecate"
252252
- CACHE_NAME="35_numpy_dev"
253253
- USE_CACHE=true
@@ -260,7 +260,7 @@ matrix:
260260
env:
261261
- PYTHON_VERSION=2.7
262262
- JOB_NAME: "27_nslow_nnet_COMPAT"
263-
- NOSE_ARGS="not slow and not network and not disabled"
263+
- TEST_ARGS="--skip-slow --skip-network"
264264
- LOCALE_OVERRIDE="it_IT.UTF-8"
265265
- INSTALL_TEST=true
266266
- JOB_TAG=_COMPAT
@@ -275,7 +275,7 @@ matrix:
275275
- PYTHON_VERSION=3.5
276276
- JOB_NAME: "35_ascii"
277277
- JOB_TAG=_ASCII
278-
- NOSE_ARGS="not slow and not network and not disabled"
278+
- TEST_ARGS="--skip-slow --skip-network"
279279
- LOCALE_OVERRIDE="C"
280280
- CACHE_NAME="35_ascii"
281281
- USE_CACHE=true

Diff for: appveyor.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ environment:
1414
# /E:ON and /V:ON options are not enabled in the batch script intepreter
1515
# See: http://stackoverflow.com/a/13751649/163740
1616
CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\ci\\run_with_env.cmd"
17+
clone_folder: C:\projects\pandas
1718

1819
matrix:
1920

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

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

9495
test_script:
9596
# tests
96-
- cd \
9797
- cmd: activate pandas
9898
- cmd: conda list
99-
- cmd: nosetests --exe -A "not slow and not network and not disabled" pandas
99+
- cmd: cd \
100+
- cmd: python -c "import pandas; pandas.test(['--skip-slow', '--skip-network'])"
101+

Diff for: ci/install_test.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ if [ "$INSTALL_TEST" ]; then
88
conda uninstall cython || exit 1
99
python "$TRAVIS_BUILD_DIR"/setup.py sdist --formats=zip,gztar || exit 1
1010
pip install "$TRAVIS_BUILD_DIR"/dist/*tar.gz || exit 1
11-
nosetests --exe -A "$NOSE_ARGS" pandas/tests/test_series.py --with-xunit --xunit-file=/tmp/nosetests_install.xml
11+
# nosetests --exe -A "$TEST_ARGS" pandas/tests/test_series.py --with-xunit --xunit-file=/tmp/nosetests_install.xml
12+
pytest pandas/tests/test_series.py --junitxml=/tmp/pytest_install.xml
1213
else
1314
echo "Skipping installation test."
1415
fi

Diff for: ci/install_travis.sh

+6-5
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,17 @@ else
8383

8484
# Useful for debugging any issues with conda
8585
conda info -a || exit 1
86+
8687
fi
8788

8889
# may have installation instructions for this build
8990
INSTALL="ci/install-${PYTHON_VERSION}${JOB_TAG}.sh"
9091
if [ -e ${INSTALL} ]; then
9192
time bash $INSTALL || exit 1
9293
else
93-
9494
# create new env
95-
time conda create -n pandas python=$PYTHON_VERSION nose || exit 1
95+
time conda create -n pandas python=$PYTHON_VERSION nose pytest || exit 1
9696

97-
if [ "$COVERAGE" ]; then
98-
pip install coverage
99-
fi
10097
if [ "$LINT" ]; then
10198
conda install flake8
10299
pip install cpplint
@@ -119,6 +116,10 @@ fi
119116

120117
source activate pandas
121118

119+
if [ "$COVERAGE" ]; then
120+
pip install coverage pytest-cov
121+
fi
122+
122123
if [ "$BUILD_TEST" ]; then
123124

124125
# build testing

Diff for: ci/requirements_all.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
nose
2+
pytest
3+
pytest-cov
24
flake8
35
sphinx
46
ipython

Diff for: ci/requirements_dev.txt

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ pytz
33
numpy
44
cython
55
nose
6+
pytest
7+
pytest-cov
68
flake8

Diff for: ci/script.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ fi
2020
if [ "$BUILD_TEST" ]; then
2121
echo "We are not running nosetests as this is simply a build test."
2222
elif [ "$COVERAGE" ]; then
23-
echo nosetests --exe -A "$NOSE_ARGS" pandas --with-coverage --with-xunit --xunit-file=/tmp/nosetests.xml
24-
nosetests --exe -A "$NOSE_ARGS" pandas --with-coverage --cover-package=pandas --cover-tests --with-xunit --xunit-file=/tmp/nosetests.xml
23+
echo pytest -s --cov=pandas --cov-report xml:/tmp/nosetests.xml $TEST_ARGS pandas
24+
pytest -s --cov=pandas --cov-report xml:/tmp/nosetests.xml $TEST_ARGS pandas
2525
else
26-
echo nosetests --exe -A "$NOSE_ARGS" pandas --doctest-tests --with-xunit --xunit-file=/tmp/nosetests.xml
27-
nosetests --exe -A "$NOSE_ARGS" pandas --doctest-tests --with-xunit --xunit-file=/tmp/nosetests.xml
26+
echo pytest $TEST_ARGS pandas
27+
pytest $TEST_ARGS pandas # TODO: doctest
2828
fi
2929

3030
RET="$?"

Diff for: doc/source/contributing.rst

+16-8
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,8 @@ use cases and writing corresponding tests.
552552
Adding tests is one of the most common requests after code is pushed to *pandas*. Therefore,
553553
it is worth getting in the habit of writing tests ahead of time so this is never an issue.
554554

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

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

598-
nosetests pandas
598+
pytest pandas
599599

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

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

608-
.. versionadded:: 0.18.0
606+
pytest pandas/path/to/test.py -k regex_matching_test_name
607+
608+
Or with one of the following constructs::
609+
610+
pytest pandas/tests/[test-module].py
611+
pytest pandas/tests/[test-module].py::[TestClass]
612+
pytest pandas/tests/[test-module].py::[TestClass]::[test_method]
613+
614+
For more, see the `pytest<http://doc.pytest.org/en/latest/>`_ documentation.
615+
616+
.. versionadded:: 0.18.0
609617

610618
Furthermore one can run
611619

Diff for: doc/source/install.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ Running the test suite
188188
pandas is equipped with an exhaustive set of unit tests covering about 97% of
189189
the codebase as of this writing. To run it on your machine to verify that
190190
everything is working (and you have all of the dependencies, soft and hard,
191-
installed), make sure you have `nose
192-
<https://nose.readthedocs.io/en/latest/>`__ and run:
191+
installed), make sure you have `pytest
192+
<http://doc.pytest.org/en/latest/>`__ and run:
193193

194194
::
195195

Diff for: doc/source/whatsnew/v0.20.0.txt

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Highlights include:
1111

1212
- Building pandas for development now requires ``cython >= 0.23`` (:issue:`14831`)
1313
- The ``.ix`` indexer has been deprecated, see :ref:`here <whatsnew_0200.api_breaking.deprecate_ix>`
14+
- Switched the test framework to `pytest`_ (:issue:`13097`)
15+
16+
.. _pytest: http://doc.pytest.org/en/latest/
1417

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

Diff for: pandas/__init__.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@
5656

5757
from pandas.io.api import *
5858

59-
# define the testing framework
60-
import pandas.util.testing
61-
from pandas.util.nosetester import NoseTester
62-
test = NoseTester().test
63-
del NoseTester
59+
from pandas.util._tester import test
6460

6561
# use the closest tagged version if possible
6662
from ._version import get_versions

Diff for: pandas/api/tests/test_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class TestPDApi(Base, tm.TestCase):
2828

2929
# these are optionally imported based on testing
3030
# & need to be ignored
31-
ignored = ['tests', 'locale']
31+
ignored = ['tests', 'locale', 'conftest']
3232

3333
# top-level sub-packages
3434
lib = ['api', 'compat', 'computation', 'core',

Diff for: pandas/conftest.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pytest
2+
3+
4+
def pytest_addoption(parser):
5+
parser.addoption("--skip-slow", action="store_true",
6+
help="skip slow tests")
7+
parser.addoption("--skip-network", action="store_true",
8+
help="run network tests")
9+
parser.addoption("--only-slow", action="store_true",
10+
help="run only slow tests")
11+
12+
13+
def pytest_runtest_setup(item):
14+
if 'slow' in item.keywords and item.config.getoption("--skip-slow"):
15+
pytest.skip("skipping due to --skip-slow")
16+
17+
if 'slow' not in item.keywords and item.config.getoption("--only-slow"):
18+
pytest.skip("skipping due to --only-slow")
19+
20+
if 'skip' in item.keywords and item.config.getoption("--skip-network"):
21+
pytest.skip("skipping due to --skip-network")

Diff for: pandas/io/tests/parser/test_network.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TestCompressedUrl(object):
2424
'xz': '.xz',
2525
}
2626

27-
def __init__(self):
27+
def setup(self):
2828
path = os.path.join(tm.get_data_path(), 'salaries.csv')
2929
self.local_table = read_table(path)
3030
self.base_url = ('https://github.com/pandas-dev/pandas/raw/master/'

0 commit comments

Comments
 (0)