Skip to content

DOC: test organization #37637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 11, 2020
1 change: 1 addition & 0 deletions doc/source/development/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ Development
policies
roadmap
meeting
test_writing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe put after internals

103 changes: 103 additions & 0 deletions doc/source/development/test_writing.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
.. _test_organization:

Test organization
=================
Ideally, there should be one, and only one, obvious place for a test to reside.
Until we reach that ideal, these are some rules of thumb for where a test should
be located.

1. Does your test depend only on code in ``pd._libs.tslibs``?
This test likely belongs in one of:

- tests.tslibs

.. note::

No file in ``tests.tslibs`` should import from any pandas modules outside of ``pd._libs.tslibs``

- tests.scalar
- tests.tseries.offsets

2. Does your test depend only on code in pd._libs?
This test likely belongs in one of:

- tests.libs
- tests.groupby.test_libgroupby

3. Is your test for an arithmetic or comparison method?
This test likely belongs in one of:

- tests.arithmetic

.. note::

These are intended for tests that can be shared to test the behavior of DataFrame/Series/Index/ExtensionArray using the ``box_with_array`` fixture.

- tests.frame.test_arithmetic
- tests.series.test_arithmetic

4. Is your test for a reduction method (min, max, sum, prod, ...)?
This test likely belongs in one of:

- tests.reductions

.. note::
These are intended for tests that can be shared to test the behavior of DataFrame/Series/Index/ExtensionArray.

- tests.frame.test_reductions
- tests.series.test_reductions
- tests.test_nanops

5. Is your test for a DataFrame or Series method?
A) Is the method a plotting method?
This test likely belongs in one of:

- tests.plotting

B) Is the method an IO method?
This test likely belongs in one of:

- tests.io

C) Is the method an indexing method?
i) Is the method ``loc``, ``iloc``, ``at``, or ``iat``?
This test likely belongs in one of:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you be a little more precise here (e.g. do we have criteria for putting in pandas/tests/indexing over the frame/series ones? (can be a TODO of course)


- tests.indexing.test_methodname

ii) Otherwise
This test likely belongs in one of:

- tests.frame.indexing.test_methodname
- tests.series.indexing.test_methodname

D) Otherwise
This test likely belongs in one of:

- tests.series.methods.test_mymethod
- tests.frame.methods.test_mymethod

.. note::

If a test can be shared between DataFrame/Series using the ``frame_or_series`` fixture, by convention it goes in tests.frame file.

- tests.generic.methods.test_mymethod

.. note::

The generic/methods/ directory is only for methods with tests that are fully parametrized over Series/DataFrame

6. Is your test for an Index method, not depending on Series/DataFrame?
This test likely belongs in one of:

- tests.indexes

7) Is your test for one of the pandas-provided ExtensionArrays (Categorical, DatetimeArray, TimedeltaArray, PeriodArray, IntervalArray, PandasArray, FloatArray, BoolArray, IntervalArray, StringArray)?
This test likely belongs in one of:

- tests.arrays

8) Is your test for *all* ExtensionArray subclasses (the "EA Interface")?
This test likely belongs in one of:

- tests.extension
5 changes: 5 additions & 0 deletions pandas/tests/series/methods/test_item.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
"""
Series.item method, mainly testing that we get python scalars as opposed to
numpy scalars.
"""
import pytest

from pandas import Series, Timedelta, Timestamp, date_range


class TestItem:
def test_item(self):
# We are testing that we get python scalars as opposed to numpy scalars
ser = Series([1])
result = ser.item()
assert result == 1
Expand Down