|
4 | 4 | from dataclasses import dataclass |
5 | 5 | from typing import TYPE_CHECKING |
6 | 6 |
|
7 | | -import mysql.connector |
| 7 | +import pymysql |
8 | 8 | import pytest |
9 | 9 |
|
10 | 10 | from pytest_databases._service import DockerService, ServiceContainer |
|
13 | 13 | if TYPE_CHECKING: |
14 | 14 | from collections.abc import Generator |
15 | 15 |
|
16 | | - from mysql.connector.abstracts import MySQLConnectionAbstract |
| 16 | + from pymysql import Connection |
17 | 17 |
|
18 | 18 | from pytest_databases.types import XdistIsolationLevel |
19 | 19 |
|
@@ -50,23 +50,23 @@ def _provide_mysql_service( |
50 | 50 |
|
51 | 51 | def check(_service: ServiceContainer) -> bool: |
52 | 52 | try: |
53 | | - conn = mysql.connector.connect( |
| 53 | + conn = pymysql.connect( |
54 | 54 | host=_service.host, |
55 | 55 | port=_service.port, |
56 | 56 | user=user, |
57 | 57 | database=database, |
58 | 58 | password=password, |
59 | 59 | ) |
60 | | - except mysql.connector.errors.OperationalError as exc: |
61 | | - if "Lost connection" in exc.msg: # type: ignore |
| 60 | + except pymysql.OperationalError as exc: |
| 61 | + if "Lost connection" in str(exc): |
62 | 62 | return False |
63 | 63 | raise |
64 | 64 |
|
65 | 65 | try: |
66 | 66 | with conn.cursor() as cursor: |
67 | 67 | cursor.execute("select 1 as is_available") |
68 | 68 | resp = cursor.fetchone() |
69 | | - return resp is not None and resp[0] == 1 # type: ignore |
| 69 | + return resp is not None and resp[0] == 1 |
70 | 70 | finally: |
71 | 71 | with contextlib.suppress(Exception): |
72 | 72 | conn.close() |
@@ -166,41 +166,41 @@ def mysql_8_service( |
166 | 166 |
|
167 | 167 |
|
168 | 168 | @pytest.fixture(scope="session") |
169 | | -def mysql_56_connection(mysql_56_service: MySQLService) -> Generator[MySQLConnectionAbstract, None, None]: |
170 | | - with mysql.connector.connect( |
| 169 | +def mysql_56_connection(mysql_56_service: MySQLService) -> Generator[Connection, None, None]: |
| 170 | + with pymysql.connect( |
171 | 171 | host=mysql_56_service.host, |
172 | 172 | port=mysql_56_service.port, |
173 | 173 | user=mysql_56_service.user, |
174 | 174 | database=mysql_56_service.db, |
175 | 175 | password=mysql_56_service.password, |
176 | 176 | ) as conn: |
177 | | - yield conn # type: ignore |
| 177 | + yield conn |
178 | 178 |
|
179 | 179 |
|
180 | 180 | @pytest.fixture(scope="session") |
181 | | -def mysql_57_connection(mysql_57_service: MySQLService) -> Generator[MySQLConnectionAbstract, None, None]: |
182 | | - with mysql.connector.connect( |
| 181 | +def mysql_57_connection(mysql_57_service: MySQLService) -> Generator[Connection, None, None]: |
| 182 | + with pymysql.connect( |
183 | 183 | host=mysql_57_service.host, |
184 | 184 | port=mysql_57_service.port, |
185 | 185 | user=mysql_57_service.user, |
186 | 186 | database=mysql_57_service.db, |
187 | 187 | password=mysql_57_service.password, |
188 | 188 | ) as conn: |
189 | | - yield conn # type: ignore |
| 189 | + yield conn |
190 | 190 |
|
191 | 191 |
|
192 | 192 | @pytest.fixture(scope="session") |
193 | | -def mysql_connection(mysql_8_connection: MySQLConnectionAbstract) -> MySQLConnectionAbstract: |
| 193 | +def mysql_connection(mysql_8_connection: Connection) -> Connection: |
194 | 194 | return mysql_8_connection |
195 | 195 |
|
196 | 196 |
|
197 | 197 | @pytest.fixture(scope="session") |
198 | | -def mysql_8_connection(mysql_8_service: MySQLService) -> Generator[MySQLConnectionAbstract, None, None]: |
199 | | - with mysql.connector.connect( |
| 198 | +def mysql_8_connection(mysql_8_service: MySQLService) -> Generator[Connection, None, None]: |
| 199 | + with pymysql.connect( |
200 | 200 | host=mysql_8_service.host, |
201 | 201 | port=mysql_8_service.port, |
202 | 202 | user=mysql_8_service.user, |
203 | 203 | database=mysql_8_service.db, |
204 | 204 | password=mysql_8_service.password, |
205 | 205 | ) as conn: |
206 | | - yield conn # type: ignore |
| 206 | + yield conn |
0 commit comments