@@ -598,6 +598,10 @@ Like many packages, *pandas* uses `pytest
598598extensions 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+
601605Writing tests
602606~~~~~~~~~~~~~
603607
@@ -654,7 +658,9 @@ Using ``pytest``
654658Here 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
0 commit comments