Skip to content

Commit b0c656e

Browse files
committed
DOC: Demo using pytest features in test classes
[ci skip]
1 parent 1dea6ef commit b0c656e

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

doc/source/contributing.rst

+22-11
Original file line numberDiff line numberDiff line change
@@ -614,23 +614,34 @@ the expected correct result::
614614

615615
assert_frame_equal(pivoted, expected)
616616

617-
How to use ``parametrize``
618-
~~~~~~~~~~~~~~~~~~~~~~~~~~
617+
Transitioning to ``pytest``
618+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
619619

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``.
622621

623-
.. note::
622+
.. code-block:: python
623+
624+
class TestReallyCoolFeature(tm.TestCase):
625+
....
624626
625-
*pandas* existing test structure is *mostly* classed based, meaning that you will typically find tests wrapped in a class, inheriting from ``tm.TestCase``.
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:
626629

627-
.. code-block:: python
630+
.. code-block:: python
631+
632+
def test_really_cool_feature():
633+
....
628634
629-
class TestReallyCoolFeature(tm.TestCase):
630-
....
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
631639
632-
Going forward we are moving to a more *functional* style, please see below.
640+
class TestReallyCoolFeature(object):
641+
....
633642
643+
Using ``pytest``
644+
~~~~~~~~~~~~~~~~
634645

635646
Here is an example of a self-contained set of tests that illustrate multiple features that we like to use.
636647

@@ -641,7 +652,7 @@ Here is an example of a self-contained set of tests that illustrate multiple fea
641652
- ``tm.assert_series_equal`` (and its counter part ``tm.assert_frame_equal``), for pandas object comparisons.
642653
- the typical pattern of constructing an ``expected`` and comparing versus the ``result``
643654

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.
645656

646657
.. code-block:: python
647658

0 commit comments

Comments
 (0)