Skip to content

Commit 12afff1

Browse files
authored
CI/TST: Use CI moto service instead of subprocess (#44612)
1 parent 08c688d commit 12afff1

12 files changed

+84
-57
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ jobs:
162162
data_manager:
163163
name: Test experimental data manager
164164
runs-on: ubuntu-latest
165+
services:
166+
moto:
167+
image: motoserver/moto
168+
env:
169+
AWS_ACCESS_KEY_ID: foobar_key
170+
AWS_SECRET_ACCESS_KEY: foobar_secret
171+
ports:
172+
- 5000:5000
165173
strategy:
166174
matrix:
167175
pattern: ["not slow and not network and not clipboard", "slow"]

.github/workflows/database.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ jobs:
6363
ports:
6464
- 5432:5432
6565

66+
moto:
67+
image: motoserver/moto
68+
env:
69+
AWS_ACCESS_KEY_ID: foobar_key
70+
AWS_SECRET_ACCESS_KEY: foobar_secret
71+
ports:
72+
- 5000:5000
73+
6674
steps:
6775
- name: Checkout
6876
uses: actions/checkout@v2

.github/workflows/posix.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ jobs:
4949
# https://github.community/t/concurrecy-not-work-for-push/183068/7
5050
group: ${{ github.event_name == 'push' && github.run_number || github.ref }}-${{ matrix.settings[0] }}
5151
cancel-in-progress: true
52+
services:
53+
moto:
54+
image: motoserver/moto
55+
env:
56+
AWS_ACCESS_KEY_ID: foobar_key
57+
AWS_SECRET_ACCESS_KEY: foobar_secret
58+
ports:
59+
- 5000:5000
5260

5361
steps:
5462
- name: Checkout

ci/deps/actions-38-db-min.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ dependencies:
3838
- xlrd
3939
- xlsxwriter
4040
- xlwt
41-
- moto
42-
- flask
4341

4442
# sql
4543
- psycopg2=2.8.4

ci/deps/actions-38-db.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies:
1414
# pandas dependencies
1515
- aiobotocore<2.0.0
1616
- beautifulsoup4
17+
- boto3
1718
- botocore>=1.11
1819
- dask
1920
- fastparquet>=0.4.0
@@ -22,8 +23,6 @@ dependencies:
2223
- geopandas
2324
- html5lib
2425
- matplotlib
25-
- moto>=1.3.14
26-
- flask
2726
- nomkl
2827
- numexpr
2928
- numpy=1.18

ci/deps/actions-38-locale.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ dependencies:
1414

1515
# pandas dependencies
1616
- beautifulsoup4
17-
- flask
1817
- html5lib
1918
- ipython
2019
- jinja2
2120
- jedi
2221
- lxml
2322
- matplotlib<3.3.0
24-
- moto
2523
- nomkl
2624
- numexpr
2725
- numpy<1.20 # GH#39541 compat with pyarrow<3
@@ -34,7 +32,6 @@ dependencies:
3432
- xlrd
3533
- xlsxwriter
3634
- xlwt
37-
- moto
3835
- pyarrow=1.0.1
3936
- pip
4037
- pip:

ci/deps/actions-38-slow.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dependencies:
1313

1414
# pandas dependencies
1515
- beautifulsoup4
16+
- boto3
1617
- fsspec>=0.7.4
1718
- html5lib
1819
- lxml
@@ -27,12 +28,9 @@ dependencies:
2728
- python-dateutil
2829
- pytz
2930
- s3fs>=0.4.0
30-
- moto>=1.3.14
3131
- scipy
3232
- sqlalchemy
3333
- xlrd
3434
- xlsxwriter
3535
- xlwt
36-
- moto
37-
- flask
3836
- numba

ci/deps/actions-39-slow.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ dependencies:
1515
# pandas dependencies
1616
- beautifulsoup4
1717
- bottleneck
18+
- boto3
1819
- fsspec>=0.8.0
1920
- gcsfs
2021
- html5lib
2122
- jinja2
2223
- lxml
2324
- matplotlib
24-
- moto>=1.3.14
25-
- flask
2625
- numba
2726
- numexpr
2827
- numpy

ci/deps/actions-39.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ dependencies:
1414
# pandas dependencies
1515
- beautifulsoup4
1616
- bottleneck
17+
- boto3
1718
- fsspec>=0.8.0
1819
- gcsfs
1920
- html5lib
2021
- jinja2
2122
- lxml
2223
- matplotlib
23-
- moto>=1.3.14
24-
- flask
2524
- numba
2625
- numexpr
2726
- numpy

ci/deps/azure-windows-38.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ dependencies:
1616
- blosc
1717
- bottleneck
1818
- fastparquet>=0.4.0
19-
- flask
2019
- fsspec>=0.8.0
2120
- matplotlib=3.3.2
22-
- moto>=1.3.14
2321
- numba
2422
- numexpr
2523
- numpy=1.18

ci/deps/azure-windows-39.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ dependencies:
2121
- jinja2
2222
- lxml
2323
- matplotlib
24-
- moto>=1.3.14
25-
- flask
2624
- numba
2725
- numexpr
2826
- numpy

pandas/tests/io/conftest.py

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
import logging
21
import os
32
import shlex
43
import subprocess
54
import time
65

76
import pytest
87

8+
from pandas.compat import (
9+
is_platform_arm,
10+
is_platform_mac,
11+
is_platform_windows,
12+
)
13+
914
import pandas._testing as tm
1015

1116
from pandas.io.parsers import read_csv
@@ -35,60 +40,72 @@ def feather_file(datapath):
3540

3641

3742
@pytest.fixture
38-
def s3so(worker_id):
39-
worker_id = "5" if worker_id == "master" else worker_id.lstrip("gw")
40-
return {"client_kwargs": {"endpoint_url": f"http://127.0.0.1:555{worker_id}/"}}
43+
def s3so():
44+
return {"client_kwargs": {"endpoint_url": "http://localhost:5000/"}}
4145

4246

4347
@pytest.fixture(scope="session")
4448
def s3_base(worker_id):
4549
"""
4650
Fixture for mocking S3 interaction.
4751
48-
Sets up moto server in separate process
52+
Sets up moto server in separate process locally
53+
Return url for motoserver/moto CI service
4954
"""
5055
pytest.importorskip("s3fs")
5156
pytest.importorskip("boto3")
52-
requests = pytest.importorskip("requests")
53-
logging.getLogger("requests").disabled = True
5457

5558
with tm.ensure_safe_environment_variables():
5659
# temporary workaround as moto fails for botocore >= 1.11 otherwise,
5760
# see https://github.com/spulec/moto/issues/1924 & 1952
5861
os.environ.setdefault("AWS_ACCESS_KEY_ID", "foobar_key")
5962
os.environ.setdefault("AWS_SECRET_ACCESS_KEY", "foobar_secret")
60-
61-
pytest.importorskip("moto", minversion="1.3.14")
62-
pytest.importorskip("flask") # server mode needs flask too
63-
64-
# Launching moto in server mode, i.e., as a separate process
65-
# with an S3 endpoint on localhost
66-
67-
worker_id = "5" if worker_id == "master" else worker_id.lstrip("gw")
68-
endpoint_port = f"555{worker_id}"
69-
endpoint_uri = f"http://127.0.0.1:{endpoint_port}/"
70-
71-
# pipe to null to avoid logging in terminal
72-
with subprocess.Popen(
73-
shlex.split(f"moto_server s3 -p {endpoint_port}"),
74-
stdout=subprocess.DEVNULL,
75-
stderr=subprocess.DEVNULL,
76-
) as proc:
77-
78-
timeout = 5
79-
while timeout > 0:
80-
try:
81-
# OK to go once server is accepting connections
82-
r = requests.get(endpoint_uri)
83-
if r.ok:
84-
break
85-
except Exception:
86-
pass
87-
timeout -= 0.1
88-
time.sleep(0.1)
89-
yield endpoint_uri
90-
91-
proc.terminate()
63+
if os.environ.get("PANDAS_CI", "0") == "1":
64+
if is_platform_arm() or is_platform_mac() or is_platform_windows():
65+
# NOT RUN on Windows/MacOS/ARM, only Ubuntu
66+
# - subprocess in CI can cause timeouts
67+
# - Azure pipelines/Github Actions do not support
68+
# container services for the above OSs
69+
# - CircleCI will probably hit the Docker rate pull limit
70+
pytest.skip(
71+
"S3 tests do not have a corresponding service in "
72+
"Windows, MacOS or ARM platforms"
73+
)
74+
else:
75+
yield "http://localhost:5000"
76+
else:
77+
requests = pytest.importorskip("requests")
78+
pytest.importorskip("moto", minversion="1.3.14")
79+
pytest.importorskip("flask") # server mode needs flask too
80+
81+
# Launching moto in server mode, i.e., as a separate process
82+
# with an S3 endpoint on localhost
83+
84+
worker_id = "5" if worker_id == "master" else worker_id.lstrip("gw")
85+
endpoint_port = f"555{worker_id}"
86+
endpoint_uri = f"http://127.0.0.1:{endpoint_port}/"
87+
88+
# pipe to null to avoid logging in terminal
89+
with subprocess.Popen(
90+
shlex.split(f"moto_server s3 -p {endpoint_port}"),
91+
stdout=subprocess.DEVNULL,
92+
stderr=subprocess.DEVNULL,
93+
) as proc:
94+
95+
timeout = 5
96+
while timeout > 0:
97+
try:
98+
# OK to go once server is accepting connections
99+
r = requests.get(endpoint_uri)
100+
if r.ok:
101+
break
102+
except Exception:
103+
pass
104+
timeout -= 0.1
105+
time.sleep(0.1)
106+
yield endpoint_uri
107+
108+
proc.terminate()
92109

93110

94111
@pytest.fixture()

0 commit comments

Comments
 (0)