Skip to content

Commit e92dd2f

Browse files
authored
ARROW-143 Switch to Pytest as Test Runner (#126)
1 parent a3c0f98 commit e92dd2f

File tree

8 files changed

+31
-26
lines changed

8 files changed

+31
-26
lines changed

.github/workflows/test-python.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ concurrency:
1212
defaults:
1313
run:
1414
working-directory: ./bindings/python
15-
shell: bash
15+
shell: bash -eux {0}
1616

1717
jobs:
1818

@@ -44,6 +44,10 @@ jobs:
4444
python-version: ${{ matrix.python-version }}
4545
cache: 'pip'
4646
cache-dependency-path: '**/setup.cfg'
47+
- name: Set up env
48+
run: |
49+
echo "LIBBSON_INSTALL_DIR=$PWD/libbson" >> $GITHUB_ENV
50+
echo "LD_LIBRARY_PATH=$PWD/libbson/lib" >> $GITHUB_ENV
4751
- name: Start MongoDB on Linux
4852
if: ${{ startsWith(runner.os, 'Linux') }}
4953
uses: supercharge/[email protected]
@@ -65,22 +69,23 @@ jobs:
6569
net start MongoDB
6670
- name: Install libbson
6771
run: |
68-
LIBBSON_INSTALL_DIR=$(pwd)/libbson ./build-libbson.sh
72+
./build-libbson.sh
6973
- name: Install Python dependencies
7074
run: |
7175
python -m pip install -U pip
7276
- name: Install pymongoarrow
7377
run: |
7478
# Install the library with no deps
75-
LIBBSON_INSTALL_DIR=$(pwd)/libbson python -m pip install -vv -e "."
79+
python -m pip install -v -e "."
7680
- name: Ensure imports with no test deps
7781
run: |
7882
python -c "from pymongoarrow.monkey import patch_all; patch_all()"
79-
- name: Run tests
83+
- name: Install the test dependencies
84+
run: |
85+
python -m pip install -v -e ".[test]"
86+
- name: Run the tests
8087
run: |
81-
# Install the test deps
82-
LIBBSON_INSTALL_DIR=$(pwd)/libbson python -m pip install -vv -e ".[test]"
83-
PYTHONWARNINGS=error LD_LIBRARY_PATH=$(pwd)/libbson/lib python -m unittest discover test -v
88+
PYTHONWARNINGS=error python -m pytest -vv
8489
- name: Check the manifest
8590
run: |
8691
pip install check-manifest

bindings/python/docs/source/developer/installation.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Test
7272
To run the test suite, you will need a MongoDB instance running on
7373
``localhost`` using port ``27017``. To run the entire test suite, do::
7474

75-
(pymongoarrow) $ python -m unittest discover test
75+
(pymongoarrow) $ python -m pytest
7676

7777
Running Linters
7878
---------------

bindings/python/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ exclude =
4747
docs
4848

4949
[options.extras_require]
50-
test = pandas;pytz
50+
test = pandas;pytz;pytest

bindings/python/test/test_arrow.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import unittest.mock as mock
1818
from datetime import datetime
1919
from test import client_context
20-
from test.utils import AllowListEventListener, TestNullsBase
20+
from test.utils import AllowListEventListener, NullsTestMixin
2121

2222
import pyarrow
2323
import pymongo
@@ -39,7 +39,7 @@
3939
from pytz import timezone
4040

4141

42-
class TestArrowApiMixin:
42+
class ArrowApiTestMixin:
4343
@classmethod
4444
def setUpClass(cls):
4545
if not client_context.connected:
@@ -468,15 +468,15 @@ def test_empty_nested_objects(self):
468468
self.round_trip(data, Schema(schema))
469469

470470

471-
class TestArrowExplicitApi(TestArrowApiMixin, unittest.TestCase):
471+
class TestArrowExplicitApi(ArrowApiTestMixin, unittest.TestCase):
472472
def run_find(self, *args, **kwargs):
473473
return find_arrow_all(self.coll, *args, **kwargs)
474474

475475
def run_aggregate(self, *args, **kwargs):
476476
return aggregate_arrow_all(self.coll, *args, **kwargs)
477477

478478

479-
class TestArrowPatchedApi(TestArrowApiMixin, unittest.TestCase):
479+
class TestArrowPatchedApi(ArrowApiTestMixin, unittest.TestCase):
480480
@classmethod
481481
def setUpClass(cls):
482482
patch_all()
@@ -528,7 +528,7 @@ def test_find_decimal128(self):
528528
self.assertEqual(table, expected)
529529

530530

531-
class TestNulls(TestNullsBase):
531+
class TestNulls(NullsTestMixin, unittest.TestCase):
532532
def find_fn(self, coll, query, schema):
533533
return find_arrow_all(coll, query, schema=schema)
534534

bindings/python/test/test_builders.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from pymongoarrow.types import ObjectIdType
3131

3232

33-
class TestIntBuildersMixin:
33+
class IntBuildersTestMixin:
3434
def test_simple(self):
3535
builder = self.builder_cls()
3636
builder.append(0)
@@ -45,13 +45,13 @@ def test_simple(self):
4545
self.assertEqual(arr.type, self.data_type)
4646

4747

48-
class TestInt32Builder(TestCase, TestIntBuildersMixin):
48+
class TestInt32Builder(TestCase, IntBuildersTestMixin):
4949
def setUp(self):
5050
self.builder_cls = Int32Builder
5151
self.data_type = int32()
5252

5353

54-
class TestInt64Builder(TestCase, TestIntBuildersMixin):
54+
class TestInt64Builder(TestCase, IntBuildersTestMixin):
5555
def setUp(self):
5656
self.builder_cls = Int64Builder
5757
self.data_type = int64()
@@ -186,7 +186,7 @@ def test_nested(self):
186186
self.assertEqual(len(arr), 9)
187187

188188

189-
class TestBoolBuilderMixin:
189+
class BoolBuilderTestMixin:
190190
def test_simple(self):
191191
builder = BoolBuilder()
192192
builder.append(False)
@@ -201,7 +201,7 @@ def test_simple(self):
201201
self.assertEqual(arr.type, self.data_type)
202202

203203

204-
class TestBoolBuilder(TestCase, TestBoolBuilderMixin):
204+
class TestBoolBuilder(TestCase, BoolBuilderTestMixin):
205205
def setUp(self):
206206
self.builder_cls = BoolBuilder
207207
self.data_type = bool_()

bindings/python/test/test_numpy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import datetime
1616
import unittest
1717
from test import client_context
18-
from test.utils import AllowListEventListener, TestNullsBase
18+
from test.utils import AllowListEventListener, NullsTestMixin
1919
from unittest import mock
2020

2121
import numpy as np
@@ -311,7 +311,7 @@ def test_find_decimal128(self):
311311

312312
# The spec for pyarrow says to_numpy is experimental, so we should expect
313313
# this to change in the future.
314-
class TestNulls(TestNullsBase, NumpyTestBase):
314+
class TestNulls(NullsTestMixin, NumpyTestBase):
315315
def table_from_dict(self, d, schema=None):
316316
out = {}
317317
for k, v in d.items():

bindings/python/test/test_pandas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import unittest.mock as mock
1919
import warnings
2020
from test import client_context
21-
from test.utils import AllowListEventListener, TestNullsBase
21+
from test.utils import AllowListEventListener, NullsTestMixin
2222

2323
import numpy as np
2424
import pandas as pd
@@ -347,7 +347,7 @@ def test_find_decimal128(self):
347347
pd.testing.assert_frame_equal(expected, table)
348348

349349

350-
class TestNulls(TestNullsBase):
350+
class TestNulls(NullsTestMixin, unittest.TestCase):
351351
def find_fn(self, coll, query, schema):
352352
return find_pandas_all(coll, query, schema=schema)
353353

bindings/python/test/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def failed(self, event):
7272
super(AllowListEventListener, self).failed(event)
7373

7474

75-
class TestNullsBase(unittest.TestCase):
75+
class NullsTestMixin:
7676
def find_fn(self, coll, query, schema):
7777
raise NotImplementedError
7878

@@ -121,7 +121,7 @@ def na_safe(self, atype):
121121

122122
@classmethod
123123
def setUpClass(cls):
124-
if cls is TestNullsBase:
124+
if cls is NullsTestMixin:
125125
raise unittest.SkipTest("Base class")
126126

127127
if not client_context.connected:
@@ -193,7 +193,7 @@ def test_other_handling(self):
193193
# arrow/pandas/numpy.
194194
for gen in [str, float, datetime.datetime, ObjectId, Decimal128]:
195195
con_type = self.pytype_tab_map[gen] # Arrow/Pandas/Numpy
196-
pytype = TestNullsBase.pytype_tab_map[gen] # Arrow type specifically
196+
pytype = NullsTestMixin.pytype_tab_map[gen] # Arrow type specifically
197197

198198
other_schema = Schema({"_id": ObjectIdType(), "other": pytype})
199199
others = [

0 commit comments

Comments
 (0)