You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/source/contributing.rst
+22-12
Original file line number
Diff line number
Diff line change
@@ -614,23 +614,34 @@ the expected correct result::
614
614
615
615
assert_frame_equal(pivoted, expected)
616
616
617
-
How to use ``parametrize``
618
-
~~~~~~~~~~~~~~~~~~~~~~~~~~
617
+
Transitioning to ``pytest``
618
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
619
619
620
-
`pytest <http://doc.pytest.org/en/latest/>`__ has a nice feature `parametrize <https://docs.pytest.org/en/latest/parametrize.html>`__ to allow
621
-
testing of many cases in a concise way that enables an easy-to-read syntax.
620
+
*pandas* existing test structure is *mostly* classed based, meaning that you will typically find tests wrapped in a class, inheriting from ``tm.TestCase``.
622
621
623
-
.. note::
622
+
.. code-block:: python
624
623
625
-
*pandas* existing test structure is *mostly* classed based, meaning that you will typically find tests wrapped in a class, inheriting from ``tm.TestCase``.
624
+
classTestReallyCoolFeature(tm.TestCase):
625
+
....
626
626
627
-
.. code-block:: python
627
+
Going forward, we are moving to a more *functional* style using the `pytest <http://doc.pytest.org/en/latest/>`__ framework, which offers a richer testing
628
+
framework that will facilitate testing and developing. Thus, instead of writing test classes, we will write test functions like this:
628
629
629
-
classTestReallyCoolFeature(tm.TestCase):
630
-
....
630
+
.. code-block:: python
631
631
632
-
Going forward we are moving to a more *functional* style, please see below.
632
+
deftest_really_cool_feature():
633
+
....
633
634
635
+
Sometimes, it does make sense to bundle test functions together into a single class, either because the test file is testing multiple functions from a single module, and
636
+
using test classes allows for better organization. However, instead of inheriting from ``tm.TestCase``, we should just inherit from ``object``:
637
+
638
+
.. code-block:: python
639
+
640
+
classTestReallyCoolFeature(object):
641
+
....
642
+
643
+
Using ``pytest``
644
+
~~~~~~~~~~~~~~~~
634
645
635
646
Here is an example of a self-contained set of tests that illustrate multiple features that we like to use.
636
647
@@ -641,7 +652,7 @@ Here is an example of a self-contained set of tests that illustrate multiple fea
641
652
- ``tm.assert_series_equal`` (and its counter part ``tm.assert_frame_equal``), for pandas object comparisons.
642
653
- the typical pattern of constructing an ``expected`` and comparing versus the ``result``
643
654
644
-
We would name this file ``test_cool_feature.py`` and put in an appropriate place in the ``pandas/tests/`` sturcture.
655
+
We would name this file ``test_cool_feature.py`` and put in an appropriate place in the ``pandas/tests/`` structure.
645
656
646
657
.. code-block:: python
647
658
@@ -701,7 +712,6 @@ Tests that we have ``parametrized`` are now accessible via the test name, for ex
0 commit comments