@@ -598,6 +598,10 @@ Like many packages, *pandas* uses `pytest
598
598
extensions in `numpy.testing
599
599
<http://docs.scipy.org/doc/numpy/reference/routines.testing.html> `_.
600
600
601
+ .. note ::
602
+
603
+ The earliest supported pytest version is 3.1.0.
604
+
601
605
Writing tests
602
606
~~~~~~~~~~~~~
603
607
@@ -654,7 +658,9 @@ Using ``pytest``
654
658
Here is an example of a self-contained set of tests that illustrate multiple features that we like to use.
655
659
656
660
- 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 ``.
657
662
- using ``parametrize ``: allow testing of multiple cases
663
+ - to set a mark on a parameter, ``pytest.param(..., marks=...) `` syntax should be used
658
664
- ``fixture ``, code for object construction, on a per-test basis
659
665
- using bare ``assert `` for scalars and truth-testing
660
666
- ``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
673
679
def test_dtypes (dtype ):
674
680
assert str (np.dtype(dtype)) == dtype
675
681
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_floats (dtype ):
687
+ assert str (np.dtype(dtype)) == dtype
688
+
676
689
@pytest.fixture
677
690
def series ():
678
691
return pd.Series([1 , 2 , 3 ])
@@ -695,13 +708,16 @@ A test run of this yields
695
708
696
709
(( pandas) bash- 3 .2 $ pytest test_cool_feature.py - v
697
710
=========================== 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 .5 .2 , pytest-3 .2 . 1 , py-1 .4 .31 , pluggy-0 .4 .0
712
+ collected 11 items
700
713
701
714
tester.py::test_dtypes[int8 ] PASSED
702
715
tester.py::test_dtypes[int16 ] PASSED
703
716
tester.py::test_dtypes[int32 ] PASSED
704
717
tester.py::test_dtypes[int64 ] PASSED
718
+ tester.py::test_floats[float32 ] PASSED
719
+ tester.py::test_floats[int16 ] SKIPPED
720
+ tester.py::test_floats[int32 ] XPASS
705
721
tester.py::test_series[int8 ] PASSED
706
722
tester.py::test_series[int16 ] PASSED
707
723
tester.py::test_series[int32 ] PASSED
0 commit comments