Skip to content

Commit 01c903a

Browse files
authored
Enable tests for asyncmy (#1833)
* Enable tests for asyncmy * Set read_timeout just for asyncmy * reuse test_mysql
1 parent fffd8aa commit 01c903a

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

Makefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ up:
2525
deps:
2626
@poetry install -E asyncpg -E aiomysql -E accel -E psycopg -E asyncodbc
2727

28+
deps_with_asyncmy:
29+
@poetry install -E asyncpg -E asyncmy -E accel -E psycopg -E asyncodbc
30+
2831
check: deps build _check
2932
_check:
3033
ifneq ($(shell which black),)
@@ -67,13 +70,20 @@ test_mysql_myisam:
6770
test_mysql:
6871
$(py_warn) TORTOISE_TEST_DB="mysql://root:$(TORTOISE_MYSQL_PASS)@127.0.0.1:3306/test_\{\}" pytest $(pytest_opts) --cov-append --cov-report=
6972

73+
test_mysql_asyncmy:
74+
$(MAKE) deps_with_asyncmy
75+
$(MAKE) test_mysql
76+
# Restore dependencies to the default
77+
$(MAKE) deps
78+
7079
test_mssql:
7180
$(py_warn) TORTOISE_TEST_DB="mssql://sa:$(TORTOISE_MSSQL_PASS)@127.0.0.1:1433/test_\{\}?driver=$(TORTOISE_MSSQL_DRIVER)&TrustServerCertificate=YES" pytest $(pytest_opts) --cov-append --cov-report=
7281

7382
test_oracle:
7483
$(py_warn) TORTOISE_TEST_DB="oracle://SYSTEM:$(TORTOISE_ORACLE_PASS)@127.0.0.1:1521/test_\{\}?driver=$(TORTOISE_ORACLE_DRIVER)" pytest $(pytest_opts) --cov-append --cov-report=
7584

76-
_testall: test_sqlite test_postgres_asyncpg test_postgres_psycopg test_mysql_myisam test_mysql test_mssql
85+
_testall: test_sqlite test_postgres_asyncpg test_postgres_psycopg test_mysql_myisam test_mysql test_mysql_asyncmy test_mssql
86+
7787
coverage report
7888

7989
testall: deps _testall

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Tortoise ORM currently supports the following databases:
152152

153153
* `SQLite` (requires ``aiosqlite``)
154154
* `PostgreSQL` (requires ``asyncpg``)
155-
* `MySQL` (requires ``asyncmy``)
155+
* `MySQL` (requires ``asyncmy`` or ``aiomysql``)
156156
* `Microsoft SQL Server`/`Oracle` (requires ``asyncodbc``)
157157

158158
``generate_schema`` generates the schema on an empty database. Tortoise generates schemas in safe mode by default which

tests/backends/test_mysql.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ async def test_bad_charset(self):
2929
async def test_ssl_true(self):
3030
self.db_config["connections"]["models"]["credentials"]["ssl"] = True
3131
try:
32-
await Tortoise.init(self.db_config, _create_db=True)
33-
except (ConnectionError, ssl.SSLError):
32+
import asyncmy # noqa pylint: disable=unused-import
33+
34+
# setting read_timeout for asyncmy. Otherwise, it will hang forever.
35+
self.db_config["connections"]["models"]["credentials"]["read_timeout"] = 1
36+
except ImportError:
3437
pass
35-
else:
36-
self.assertFalse(True, "Expected ConnectionError or SSLError")
38+
39+
with self.assertRaises(ConnectionError):
40+
await Tortoise.init(self.db_config, _create_db=True)
3741

3842
async def test_ssl_custom(self):
3943
# Expect connectionerror or pass

0 commit comments

Comments
 (0)