Skip to content

Commit 90c2fbc

Browse files
committed
DOC: Demo using pytest features in test classes
[ci skip]
1 parent 2b9d948 commit 90c2fbc

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

doc/source/contributing.rst

+14-2
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ testing of many cases in a concise way that enables an easy-to-read syntax.
629629
class TestReallyCoolFeature(tm.TestCase):
630630
....
631631
632-
Going forward we are moving to a more *functional* style, please see below.
632+
Going forward, we are moving to a more *functional* style, please see below.
633633

634634

635635
Here is an example of a self-contained set of tests that illustrate multiple features that we like to use.
@@ -641,7 +641,7 @@ Here is an example of a self-contained set of tests that illustrate multiple fea
641641
- ``tm.assert_series_equal`` (and its counter part ``tm.assert_frame_equal``), for pandas object comparisons.
642642
- the typical pattern of constructing an ``expected`` and comparing versus the ``result``
643643

644-
We would name this file ``test_cool_feature.py`` and put in an appropriate place in the ``pandas/tests/`` sturcture.
644+
We would name this file ``test_cool_feature.py`` and put in an appropriate place in the ``pandas/tests/`` structure.
645645

646646
.. code-block:: python
647647
@@ -701,6 +701,18 @@ Tests that we have ``parametrized`` are now accessible via the test name, for ex
701701
test_cool_feature.py::test_dtypes[int8] PASSED
702702
test_cool_feature.py::test_series[int8] PASSED
703703
704+
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
705+
using test classes allows for better organization. However, instead of inheriting from ``tm.TestCase``, we just inherit from ``object``, and we can parametrize as before:
706+
707+
708+
.. code-block:: python
709+
710+
class TestReallyCoolFeature(object):
711+
712+
@pytest.mark.parametrize('dtype', ['int8', 'int16', 'int32', 'int64'])
713+
def test_dtypes(self, dtype):
714+
assert str(np.dtype(dtype)) == dtype
715+
704716
705717
Running the test suite
706718
----------------------

0 commit comments

Comments
 (0)