Testing πŸ§ͺΒΆ

In this section we outline steps needed for unit testing in Arrow.

We use pytest for unit tests in Python. For more info about the required packages see Python unit testing section.

Structure

Test layout in PyArrow follows pytest structure for Tests as part of application code:

pyarrow/
    __init__.py
    csv.py
    dataset.py
    ...
    tests/
        __init__.py
        test_csv.py
        test_dataset.py
        ...

Tests for Parquet are located in a separate folder pyarrow/tests/parquet/.

Running tests

To run a specific unit test, use this command in the terminal from the arrow/python folder:

$ pytest pyarrow/tests/test_file.py -k test_your_unit_test

Run all the tests from one file:

$ pytest pyarrow/tests/test_file.py

Run all the tests:

$ pytest pyarrow

You can also run the tests with python -m pytest [...] which is almost equivalent to using pytest [...] directly, except that calling via python will also add the current directory to sys.path and can in some cases help if pytest [...] results in an ImportError.

Recompiling PyArrow or Arrow C++

If the tests start failing, try to recompile PyArrow or Arrow C++. See note in the Building other Arrow libraries section under the PyArrow tab.

Fixtures

Inside PyArrow test files there can be helper functions and fixtures defined. Also other pytest decorators such as @parametrize or @skipif are used.

For example:

  • _alltypes_example in test_pandas supplies a dataframe with 100 rows for all data types.

  • _check_pandas_roundtrip in test_pandas asserts if the roundtrip from Pandas through pa.Table or pa.RecordBatch back to Pandas yields the same result.

  • large_buffer fixture supplying a PyArrow buffer of fixed size to the function test_primitive_serialization(large_buffer) in test_serialization.py.

For this reason it is good to look through the file you are planning to add the tests to and see if any of the defined functions or fixtures will be helpful.

For more information about pytest in general visit Full pytest documentation