Skip to content

Commit db3ea2f

Browse files
swyoonjowens
authored andcommitted
TST: pytest deprecation warnings GH17197 (pandas-dev#17253)
Test parameters with marks are updated according to the updated API of Pytest. https://docs.pytest.org/en/latest/changelog.html#pytest-3-2-0-2017-07-30 https://docs.pytest.org/en/latest/parametrize.html
1 parent a618bec commit db3ea2f

11 files changed

+52
-26
lines changed

appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ install:
7272
- cmd: conda info -a
7373

7474
# create our env
75-
- cmd: conda create -n pandas python=%PYTHON_VERSION% cython pytest pytest-xdist
75+
- cmd: conda create -n pandas python=%PYTHON_VERSION% cython pytest>=3.1.0 pytest-xdist
7676
- cmd: activate pandas
7777
- SET REQ=ci\requirements-%PYTHON_VERSION%_WIN.run
7878
- cmd: echo "installing requirements from %REQ%"

ci/install_circle.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fi
6464
# create envbuild deps
6565
echo "[create env: ${REQ_BUILD}]"
6666
time conda create -n pandas -q --file=${REQ_BUILD} || exit 1
67-
time conda install -n pandas pytest || exit 1
67+
time conda install -n pandas pytest>=3.1.0 || exit 1
6868

6969
source activate pandas
7070

ci/install_travis.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ if [ -e ${REQ} ]; then
103103
time bash $REQ || exit 1
104104
fi
105105

106-
time conda install -n pandas pytest
106+
time conda install -n pandas pytest>=3.1.0
107107
time pip install pytest-xdist
108108

109109
if [ "$LINT" ]; then

ci/requirements_all.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pytest
1+
pytest>=3.1.0
22
pytest-cov
33
pytest-xdist
44
flake8

ci/requirements_dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ python-dateutil
22
pytz
33
numpy
44
cython
5-
pytest
5+
pytest>=3.1.0
66
pytest-cov
77
flake8

doc/source/contributing.rst

+20-4
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,10 @@ Like many packages, *pandas* uses `pytest
598598
extensions in `numpy.testing
599599
<http://docs.scipy.org/doc/numpy/reference/routines.testing.html>`_.
600600

601+
.. note::
602+
603+
The earliest supported pytest version is 3.1.0.
604+
601605
Writing tests
602606
~~~~~~~~~~~~~
603607

@@ -654,7 +658,9 @@ Using ``pytest``
654658
Here is an example of a self-contained set of tests that illustrate multiple features that we like to use.
655659

656660
- functional style: tests are like ``test_*`` and *only* take arguments that are either fixtures or parameters
661+
- ``pytest.mark`` can be used to set metadata on test functions, e.g. ``skip`` or ``xfail``.
657662
- using ``parametrize``: allow testing of multiple cases
663+
- to set a mark on a parameter, ``pytest.param(..., marks=...)`` syntax should be used
658664
- ``fixture``, code for object construction, on a per-test basis
659665
- using bare ``assert`` for scalars and truth-testing
660666
- ``tm.assert_series_equal`` (and its counter part ``tm.assert_frame_equal``), for pandas object comparisons.
@@ -673,6 +679,13 @@ We would name this file ``test_cool_feature.py`` and put in an appropriate place
673679
def test_dtypes(dtype):
674680
assert str(np.dtype(dtype)) == dtype
675681
682+
@pytest.mark.parametrize('dtype', ['float32',
683+
pytest.param('int16', marks=pytest.mark.skip),
684+
pytest.param('int32',
685+
marks=pytest.mark.xfail(reason='to show how it works'))])
686+
def test_mark(dtype):
687+
assert str(np.dtype(dtype)) == 'float32'
688+
676689
@pytest.fixture
677690
def series():
678691
return pd.Series([1, 2, 3])
@@ -695,13 +708,16 @@ A test run of this yields
695708
696709
((pandas) bash-3.2$ pytest test_cool_feature.py -v
697710
=========================== test session starts ===========================
698-
platform darwin -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0
699-
collected 8 items
711+
platform darwin -- Python 3.6.2, pytest-3.2.1, py-1.4.31, pluggy-0.4.0
712+
collected 11 items
700713
701714
tester.py::test_dtypes[int8] PASSED
702715
tester.py::test_dtypes[int16] PASSED
703716
tester.py::test_dtypes[int32] PASSED
704717
tester.py::test_dtypes[int64] PASSED
718+
tester.py::test_mark[float32] PASSED
719+
tester.py::test_mark[int16] SKIPPED
720+
tester.py::test_mark[int32] xfail
705721
tester.py::test_series[int8] PASSED
706722
tester.py::test_series[int16] PASSED
707723
tester.py::test_series[int32] PASSED
@@ -714,8 +730,8 @@ Tests that we have ``parametrized`` are now accessible via the test name, for ex
714730
715731
((pandas) bash-3.2$ pytest test_cool_feature.py -v -k int8
716732
=========================== test session starts ===========================
717-
platform darwin -- Python 3.5.2, pytest-3.0.5, py-1.4.31, pluggy-0.4.0
718-
collected 8 items
733+
platform darwin -- Python 3.6.2, pytest-3.2.1, py-1.4.31, pluggy-0.4.0
734+
collected 11 items
719735
720736
test_cool_feature.py::test_dtypes[int8] PASSED
721737
test_cool_feature.py::test_series[int8] PASSED

pandas/tests/computation/test_eval.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@
3838

3939

4040
@pytest.fixture(params=(
41-
pytest.mark.skipif(engine == 'numexpr' and not _USE_NUMEXPR,
42-
reason='numexpr enabled->{enabled}, '
43-
'installed->{installed}'.format(
44-
enabled=_USE_NUMEXPR,
45-
installed=_NUMEXPR_INSTALLED))(engine)
46-
for engine in _engines # noqa
47-
))
41+
pytest.param(engine,
42+
marks=pytest.mark.skipif(
43+
engine == 'numexpr' and not _USE_NUMEXPR,
44+
reason='numexpr enabled->{enabled}, '
45+
'installed->{installed}'.format(
46+
enabled=_USE_NUMEXPR,
47+
installed=_NUMEXPR_INSTALLED)))
48+
for engine in _engines)) # noqa
4849
def engine(request):
4950
return request.param
5051

pandas/tests/io/parser/test_network.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ def salaries_table():
2323
@pytest.mark.parametrize(
2424
"compression,extension",
2525
[('gzip', '.gz'), ('bz2', '.bz2'), ('zip', '.zip'),
26-
pytest.mark.skipif(not tm._check_if_lzma(),
27-
reason='need backports.lzma to run')(('xz', '.xz'))])
26+
pytest.param('xz', '.xz',
27+
marks=pytest.mark.skipif(not tm._check_if_lzma(),
28+
reason='need backports.lzma '
29+
'to run'))])
2830
@pytest.mark.parametrize('mode', ['explicit', 'infer'])
2931
@pytest.mark.parametrize('engine', ['python', 'c'])
3032
def test_compressed_urls(salaries_table, compression, extension, mode, engine):

pandas/tests/io/test_excel.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -2400,8 +2400,10 @@ def check_called(func):
24002400

24012401

24022402
@pytest.mark.parametrize('engine', [
2403-
pytest.mark.xfail('xlwt', reason='xlwt does not support '
2404-
'openpyxl-compatible style dicts'),
2403+
pytest.param('xlwt',
2404+
marks=pytest.mark.xfail(reason='xlwt does not support '
2405+
'openpyxl-compatible '
2406+
'style dicts')),
24052407
'xlsxwriter',
24062408
'openpyxl',
24072409
])

pandas/tests/io/test_parquet.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@
2626

2727
# setup engines & skips
2828
@pytest.fixture(params=[
29-
pytest.mark.skipif(not _HAVE_FASTPARQUET,
30-
reason='fastparquet is not installed')('fastparquet'),
31-
pytest.mark.skipif(not _HAVE_PYARROW,
32-
reason='pyarrow is not installed')('pyarrow')])
29+
pytest.param('fastparquet',
30+
marks=pytest.mark.skipif(not _HAVE_FASTPARQUET,
31+
reason='fastparquet is '
32+
'not installed')),
33+
pytest.param('pyarrow',
34+
marks=pytest.mark.skipif(not _HAVE_PYARROW,
35+
reason='pyarrow is '
36+
'not installed'))])
3337
def engine(request):
3438
return request.param
3539

pandas/tests/test_window.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,9 @@ def test_numpy_compat(self):
530530

531531
@pytest.mark.parametrize(
532532
'expander',
533-
[1, pytest.mark.xfail(
534-
reason='GH 16425 expanding with offset not supported')('1s')])
533+
[1, pytest.param('ls', marks=pytest.mark.xfail(
534+
reason='GH 16425 expanding with '
535+
'offset not supported'))])
535536
def test_empty_df_expanding(self, expander):
536537
# GH 15819 Verifies that datetime and integer expanding windows can be
537538
# applied to empty DataFrames

0 commit comments

Comments
 (0)