Skip to content

Commit f3e326c

Browse files
committed
✅ handle CMySQLConnection import for compatibility with different MySQL connector builds
1 parent 1e24637 commit f3e326c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

tests/conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from docker.models.containers import Container
2121
from faker import Faker
2222
from mysql.connector import MySQLConnection, errorcode
23-
from mysql.connector.connection_cext import CMySQLConnection
2423
from mysql.connector.pooling import PooledMySQLConnection
2524
from requests import HTTPError
2625
from sqlalchemy import create_engine
@@ -31,6 +30,12 @@
3130

3231
from . import database, factories
3332

33+
try:
34+
from mysql.connector.connection_cext import CMySQLConnection
35+
except ImportError:
36+
# Free-threaded Python builds fall back to the pure-Python connector.
37+
CMySQLConnection = MySQLConnection
38+
3439

3540
def pytest_addoption(parser: "Parser") -> None:
3641
parser.addoption(

tests/func/sqlite3_to_mysql_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from _pytest.logging import LogCaptureFixture
1515
from faker import Faker
1616
from mysql.connector import MySQLConnection, errorcode
17-
from mysql.connector.connection_cext import CMySQLConnection
1817
from mysql.connector.pooling import PooledMySQLConnection
1918
from pytest_mock import MockFixture
2019
from sqlalchemy import MetaData, Table, create_engine, inspect, select, text
@@ -26,6 +25,12 @@
2625
from sqlite3_to_mysql import SQLite3toMySQL
2726
from tests.conftest import Helpers, MySQLCredentials
2827

28+
try:
29+
from mysql.connector.connection_cext import CMySQLConnection
30+
except ImportError:
31+
# Free-threaded Python builds fall back to the pure-Python connector.
32+
CMySQLConnection = MySQLConnection
33+
2934

3035
@pytest.mark.usefixtures("sqlite_database", "mysql_instance")
3136
class TestSQLite3toMySQL:

0 commit comments

Comments
 (0)