Skip to content

Commit c9fcfc4

Browse files
committed
mariadb client
1 parent d9b398f commit c9fcfc4

File tree

6 files changed

+54
-31
lines changed

6 files changed

+54
-31
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030

3131
- if: runner.os == 'Linux'
3232
name: Install Microsoft ODBC Drivers
33-
run: sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18
33+
run: sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 libmariadb-dev
3434

3535
- name: Set up Python ${{ matrix.python-version }}
3636
uses: actions/setup-python@v5

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ dragonfly = ["redis"]
6060
elasticsearch7 = ["elasticsearch7"]
6161
elasticsearch8 = ["elasticsearch8"]
6262
keydb = ["redis"]
63+
mariadb = ["mariadb"]
6364
mssql = ["pymssql<=2.3.1"]
6465
mysql = ["mysql-connector-python"]
6566
oracle = ["oracledb"]
@@ -71,7 +72,7 @@ spanner = ["google-cloud-spanner"]
7172
[dependency-groups]
7273
dev = [
7374
# tests
74-
"pytest-databases[azure-storage,bigquery,cockroachdb,dragonfly,elasticsearch7,elasticsearch8,keydb,mssql,mysql,oracle,postgres,redis,spanner]",
75+
"pytest-databases[azure-storage,bigquery,cockroachdb,dragonfly,elasticsearch7,elasticsearch8,keydb,mssql,mysql,mariadb,oracle,postgres,redis,spanner]",
7576
"coverage[toml]>=6.2",
7677
"coverage[toml]>=6.2",
7778
"pytest",

src/pytest_databases/docker/mariadb.py

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

33
import contextlib
4+
import traceback
45
from dataclasses import dataclass
56
from typing import TYPE_CHECKING, Generator
67

7-
import pymysql
8+
import mariadb
89
import pytest
910

1011
from pytest_databases.helpers import get_xdist_worker_num
@@ -42,14 +43,15 @@ def _provide_mysql_service(
4243

4344
def check(_service: ServiceContainer) -> bool:
4445
try:
45-
conn = pymysql.connect(
46+
conn = mariadb.connect(
4647
host=_service.host,
4748
port=_service.port,
4849
user=user,
4950
database=database,
5051
password=password,
5152
)
5253
except Exception: # noqa: BLE001
54+
traceback.print_exc()
5355
return False
5456

5557
try:
@@ -121,8 +123,8 @@ def mariadb_service(mariadb_113_service: MariaDBService) -> MariaDBService:
121123

122124

123125
@pytest.fixture(autouse=False, scope="session")
124-
def mariadb_113_connection(mariadb_113_service: MariaDBService) -> Generator[pymysql.Connection, None, None]:
125-
with pymysql.connect(
126+
def mariadb_113_connection(mariadb_113_service: MariaDBService) -> Generator[mariadb.Connection, None, None]:
127+
with mariadb.connect(
126128
host=mariadb_113_service.host,
127129
port=mariadb_113_service.port,
128130
user=mariadb_113_service.user,
@@ -133,5 +135,5 @@ def mariadb_113_connection(mariadb_113_service: MariaDBService) -> Generator[pym
133135

134136

135137
@pytest.fixture(autouse=False, scope="session")
136-
def mariadb_connection(mariadb_113_connection: pymysql.Connection) -> pymysql.Connection:
138+
def mariadb_connection(mariadb_113_connection: mariadb.Connection) -> mariadb.Connection:
137139
return mariadb_113_connection

src/pytest_databases/docker/mysql.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from typing import TYPE_CHECKING
66

77
import mysql.connector
8-
from mysql.connector.abstracts import MySQLConnectionAbstract
98
import pytest
109

1110
from pytest_databases._service import DockerService, ServiceContainer
@@ -14,6 +13,8 @@
1413
if TYPE_CHECKING:
1514
from collections.abc import Generator
1615

16+
from mysql.connector.abstracts import MySQLConnectionAbstract
17+
1718
from pytest_databases.types import XdistIsolationLevel
1819

1920

@@ -104,12 +105,12 @@ def check(_service: ServiceContainer) -> bool:
104105
)
105106

106107

107-
@pytest.fixture(autouse=False, scope="session")
108+
@pytest.fixture(scope="session")
108109
def mysql_service(mysql_8_service: MySQLService) -> MySQLService:
109110
return mysql_8_service
110111

111112

112-
@pytest.fixture(autouse=False, scope="session")
113+
@pytest.fixture(scope="session")
113114
def mysql_56_service(
114115
docker_service: DockerService,
115116
xdist_mysql_isolation_level: XdistIsolationLevel,
@@ -123,7 +124,7 @@ def mysql_56_service(
123124
yield service
124125

125126

126-
@pytest.fixture(autouse=False, scope="session")
127+
@pytest.fixture(scope="session")
127128
def mysql_57_service(
128129
docker_service: DockerService,
129130
xdist_mysql_isolation_level: XdistIsolationLevel,
@@ -137,7 +138,7 @@ def mysql_57_service(
137138
yield service
138139

139140

140-
@pytest.fixture(autouse=False, scope="session")
141+
@pytest.fixture(scope="session")
141142
def mysql_8_service(
142143
docker_service: DockerService,
143144
xdist_mysql_isolation_level: XdistIsolationLevel,
@@ -151,10 +152,8 @@ def mysql_8_service(
151152
yield service
152153

153154

154-
@pytest.fixture(autouse=False, scope="session")
155-
def mysql_56_connection(
156-
mysql_56_service: MySQLService,
157-
) -> Generator[MySQLConnectionAbstract, None, None]:
155+
@pytest.fixture(scope="session")
156+
def mysql_56_connection(mysql_56_service: MySQLService) -> Generator[MySQLConnectionAbstract, None, None]:
158157
with mysql.connector.connect(
159158
host=mysql_56_service.host,
160159
port=mysql_56_service.port,
@@ -165,10 +164,8 @@ def mysql_56_connection(
165164
yield conn
166165

167166

168-
@pytest.fixture(autouse=False, scope="session")
169-
def mysql_57_connection(
170-
mysql_57_service: MySQLService,
171-
) -> Generator[MySQLConnectionAbstract, None, None]:
167+
@pytest.fixture(scope="session")
168+
def mysql_57_connection(mysql_57_service: MySQLService) -> Generator[MySQLConnectionAbstract, None, None]:
172169
with mysql.connector.connect(
173170
host=mysql_57_service.host,
174171
port=mysql_57_service.port,
@@ -179,13 +176,13 @@ def mysql_57_connection(
179176
yield conn
180177

181178

182-
@pytest.fixture(autouse=False, scope="session")
183-
def mysql_connection(mysql_8_connection) -> MySQLConnectionAbstract:
179+
@pytest.fixture(scope="session")
180+
def mysql_connection(mysql_8_connection: MySQLConnectionAbstract) -> MySQLConnectionAbstract:
184181
return mysql_8_connection
185182

186183

187-
@pytest.fixture(autouse=False, scope="session")
188-
def mysql_8_connection(mysql_8_service) -> Generator[MySQLConnectionAbstract, None, None]:
184+
@pytest.fixture(scope="session")
185+
def mysql_8_connection(mysql_8_service: MySQLService) -> Generator[MySQLConnectionAbstract, None, None]:
189186
with mysql.connector.connect(
190187
host=mysql_8_service.host,
191188
port=mysql_8_service.port,

tests/test_mariadb.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
)
1313
def test_service_fixture(pytester: pytest.Pytester, service_fixture: str) -> None:
1414
pytester.makepyfile(f"""
15-
import pymysql
15+
import mariadb
16+
1617
pytest_plugins = ["pytest_databases.docker.mariadb"]
1718
1819
def test({service_fixture}):
19-
with pymysql.connect(
20+
with mariadb.connect(
2021
host={service_fixture}.host,
2122
port={service_fixture}.port,
2223
user={service_fixture}.user,
@@ -41,7 +42,6 @@ def test({service_fixture}):
4142
)
4243
def test_connection_fixture(pytester: pytest.Pytester, connection_fixture: str) -> None:
4344
pytester.makepyfile(f"""
44-
import pymysql
4545
pytest_plugins = ["pytest_databases.docker.mariadb"]
4646
4747
def test({connection_fixture}):
@@ -58,7 +58,6 @@ def test({connection_fixture}):
5858

5959
def test_xdist_isolate_database(pytester: pytest.Pytester) -> None:
6060
pytester.makepyfile("""
61-
import pymysql
6261
pytest_plugins = ["pytest_databases.docker.mariadb"]
6362
6463
def test_1(mariadb_113_connection):
@@ -76,7 +75,6 @@ def test_2(mariadb_113_connection):
7675

7776
def test_xdist_isolate_server(pytester: pytest.Pytester) -> None:
7877
pytester.makepyfile("""
79-
import pymysql
8078
import pytest
8179
pytest_plugins = ["pytest_databases.docker.mariadb"]
8280

uv.lock

Lines changed: 27 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)