Skip to content

Commit 5ba7b2d

Browse files
authored
fix: tests failing on ARM MacOS (#82)
1 parent abc016a commit 5ba7b2d

File tree

10 files changed

+111
-10
lines changed

10 files changed

+111
-10
lines changed

CONTRIBUTING.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Contribution guide
44
Setting up the environment
55
--------------------------
66

7-
1. ``make install``
7+
1. `Install MariaDB <https://mariadb.com/kb/en/binary-packages/>`_
8+
2. ``make install``
89

910
Code contributions
1011
------------------

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ clean: ## Cleanup temporary build a
118118
.PHONY: test
119119
test: ## Run the tests
120120
@echo "${INFO} Running test cases... 🧪"
121-
@uv run pytest -n 2 --quiet
121+
@uv run pytest --quiet --runpytest subprocess
122122
@echo "${OK} Tests passed ✨"
123123

124124
.PHONY: coverage

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ dev = [
8383
"pytest-xdist",
8484
"pytest-sugar",
8585
"slotscheck",
86+
"psycopg-binary", # This fixes tests failing on M series CPUs.
8687
# lint
8788
"mypy",
8889
"ruff",
@@ -111,10 +112,8 @@ dev = [
111112
"myst-parser",
112113
"sphinx-autodoc-typehints",
113114
"sphinx-rtd-theme",
114-
115115
]
116116

117-
118117
##################
119118
# External Tools #
120119
##################

src/pytest_databases/_service.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
from contextlib import AbstractContextManager, contextmanager
99
from typing import TYPE_CHECKING, Any, Callable
1010

11+
import docker
1112
import filelock
1213
import pytest
14+
from docker.errors import ImageNotFound
1315
from typing_extensions import Self
1416

15-
import docker
16-
from docker.errors import ImageNotFound
1717
from pytest_databases.helpers import get_xdist_worker_id
1818
from pytest_databases.types import ServiceContainer
1919

@@ -137,20 +137,24 @@ def run(
137137
ulimits: list[Ulimit] | None = None,
138138
shm_size: int | None = None,
139139
mem_limit: str | None = None,
140+
platform: str | None = None,
140141
) -> Generator[ServiceContainer, None, None]:
141142
if check is None and wait_for_log is None:
142143
msg = "Must set at least check or wait_for_log"
143144
raise ValueError(msg)
144145

146+
platform_kwarg = {}
147+
if platform is not None:
148+
platform_kwarg = {"platform": platform}
149+
145150
name = f"pytest_databases_{name}"
146151
lock = filelock.FileLock(self._tmp_path / name) if self._is_xdist else contextlib.nullcontext()
147-
148152
with lock:
149153
container = self._get_container(name)
150154
try:
151155
self._client.images.get(image)
152156
except ImageNotFound:
153-
self._client.images.pull(*image.rsplit(":", maxsplit=1)) # pyright: ignore[reportCallIssue,reportArgumentType]
157+
self._client.images.pull(*image.rsplit(":", maxsplit=1), **platform_kwarg) # pyright: ignore[reportCallIssue,reportArgumentType]
154158

155159
if container is None:
156160
container = self._client.containers.run( # pyright: ignore[reportCallIssue,reportArgumentType]
@@ -164,6 +168,7 @@ def run(
164168
environment=env,
165169
ulimits=ulimits,
166170
mem_limit=mem_limit,
171+
**platform_kwarg, # pyright: ignore[reportArgumentType]
167172
)
168173

169174
# reload the container; sometimes it can take a while before docker

src/pytest_databases/docker/bigquery.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ def bigquery_image() -> str:
2727
return "ghcr.io/goccy/bigquery-emulator:latest"
2828

2929

30+
@pytest.fixture(scope="session")
31+
def platform() -> str:
32+
return "linux/x86_64"
33+
34+
3035
@dataclass
3136
class BigQueryService(ServiceContainer):
3237
project: str
@@ -47,6 +52,7 @@ def bigquery_service(
4752
docker_service: DockerService,
4853
xdist_bigquery_isolation_level: XdistIsolationLevel,
4954
bigquery_image: str,
55+
platform: str,
5056
) -> Generator[BigQueryService, None, None]:
5157
project = "emulator-test-project"
5258
dataset = "test-dataset"
@@ -83,6 +89,7 @@ def check(_service: ServiceContainer) -> bool:
8389
container_port=9050,
8490
timeout=60,
8591
transient=xdist_bigquery_isolation_level == "server",
92+
platform=platform,
8693
) as service:
8794
yield BigQueryService(
8895
host=service.host,

src/pytest_databases/docker/mysql.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,18 @@ def xdist_mysql_isolation_level() -> XdistIsolationLevel:
3030
return "database"
3131

3232

33+
@pytest.fixture(scope="session")
34+
def platform() -> str:
35+
return "linux/x86_64"
36+
37+
3338
@contextlib.contextmanager
3439
def _provide_mysql_service(
3540
docker_service: DockerService,
3641
image: str,
3742
name: str,
3843
isolation_level: XdistIsolationLevel,
44+
platform: str,
3945
) -> Generator[MySQLService, None, None]:
4046
user = "app"
4147
password = "super-secret"
@@ -95,6 +101,7 @@ def check(_service: ServiceContainer) -> bool:
95101
'FLUSH PRIVILEGES;"'
96102
),
97103
transient=isolation_level == "server",
104+
platform=platform,
98105
) as service:
99106
yield MySQLService(
100107
db=db_name,
@@ -114,12 +121,14 @@ def mysql_service(mysql_8_service: MySQLService) -> MySQLService:
114121
def mysql_56_service(
115122
docker_service: DockerService,
116123
xdist_mysql_isolation_level: XdistIsolationLevel,
124+
platform: str,
117125
) -> Generator[MySQLService, None, None]:
118126
with _provide_mysql_service(
119127
image="mysql:5.6",
120128
name="mysql-56",
121129
docker_service=docker_service,
122130
isolation_level=xdist_mysql_isolation_level,
131+
platform=platform,
123132
) as service:
124133
yield service
125134

@@ -128,12 +137,14 @@ def mysql_56_service(
128137
def mysql_57_service(
129138
docker_service: DockerService,
130139
xdist_mysql_isolation_level: XdistIsolationLevel,
140+
platform: str,
131141
) -> Generator[MySQLService, None, None]:
132142
with _provide_mysql_service(
133143
image="mysql:5.7",
134144
name="mysql-57",
135145
docker_service=docker_service,
136146
isolation_level=xdist_mysql_isolation_level,
147+
platform=platform,
137148
) as service:
138149
yield service
139150

@@ -142,12 +153,14 @@ def mysql_57_service(
142153
def mysql_8_service(
143154
docker_service: DockerService,
144155
xdist_mysql_isolation_level: XdistIsolationLevel,
156+
platform: str,
145157
) -> Generator[MySQLService, None, None]:
146158
with _provide_mysql_service(
147159
image="mysql:8",
148160
name="mysql-8",
149161
docker_service=docker_service,
150162
isolation_level=xdist_mysql_isolation_level,
163+
platform=platform,
151164
) as service:
152165
yield service
153166

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from __future__ import annotations
22

3+
import platform
4+
35
import pytest
46

57
pytestmark = pytest.mark.anyio
@@ -9,3 +11,6 @@
911
"pytest_databases.docker",
1012
"pytester",
1113
]
14+
15+
PLATFORM_PROCESSOR = platform.processor()
16+
PLATFORM_SYSTEM = platform.system()

tests/test_mssql.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
import pytest
44

5+
from tests.conftest import PLATFORM_PROCESSOR
6+
57

68
@pytest.mark.parametrize(
79
"service_fixture",
810
[
911
"mssql_service",
1012
],
1113
)
14+
@pytest.mark.skipif(PLATFORM_PROCESSOR == "arm", reason="ARM bug. https://github.com/pymssql/pymssql/issues/822")
1215
def test_service_fixture(pytester: pytest.Pytester, service_fixture: str) -> None:
1316
pytester.makepyfile(f"""
1417
import pymssql
@@ -39,6 +42,7 @@ def test({service_fixture}):
3942
"mssql_connection",
4043
],
4144
)
45+
@pytest.mark.skipif(PLATFORM_PROCESSOR == "arm", reason="ARM bug. https://github.com/pymssql/pymssql/issues/822")
4246
def test_connection_fixture(pytester: pytest.Pytester, connection_fixture: str) -> None:
4347
pytester.makepyfile(f"""
4448
import pymssql
@@ -58,6 +62,7 @@ def test({connection_fixture}):
5862
result.assert_outcomes(passed=1)
5963

6064

65+
@pytest.mark.skipif(PLATFORM_PROCESSOR == "arm", reason="ARM bug. https://github.com/pymssql/pymssql/issues/822")
6166
def test_xdist_isolate_database(pytester: pytest.Pytester) -> None:
6267
pytester.makepyfile("""
6368
import pymssql
@@ -76,6 +81,7 @@ def test_2(mssql_connection):
7681
result.assert_outcomes(passed=2)
7782

7883

84+
@pytest.mark.skipif(PLATFORM_PROCESSOR == "arm", reason="ARM bug. https://github.com/pymssql/pymssql/issues/822")
7985
def test_xdist_isolate_server(pytester: pytest.Pytester) -> None:
8086
pytester.makepyfile("""
8187
import pymssql

tests/test_mysql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def test({service_fixture}):
3636
@pytest.mark.parametrize(
3737
"connection_fixture",
3838
[
39-
"mysql_56_connection",
40-
"mysql_57_connection",
39+
"mysql_56_connection",
40+
"mysql_57_connection",
4141
],
4242
)
4343
def test_connection_fixture(pytester: pytest.Pytester, connection_fixture: str) -> None:

0 commit comments

Comments
 (0)