Skip to content
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
TORTOISE_MSSQL_DRIVER: ODBC Driver 18 for SQL Server
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- uses: actions/cache@v4
with:
Expand Down
5 changes: 3 additions & 2 deletions tests/contrib/test_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
class TestDecorator(test.TestCase):
@test.requireCapability(dialect="sqlite")
async def test_script_with_init_memory_sqlite(self) -> None:
r = subprocess.run(["python", "examples/basic.py"], capture_output=True) # nosec
output = r.stdout.decode()
r = subprocess.run(["python", "examples/basic.py"], capture_output=True, text=True) # nosec
assert not r.stderr
output = r.stdout
s = "[{'id': 1, 'name': 'Updated name'}, {'id': 2, 'name': 'Test 2'}]"
self.assertIn(s, output)

Expand Down
21 changes: 17 additions & 4 deletions tests/utils/test_describe_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import json
import sys
import uuid
from typing import Union

Expand Down Expand Up @@ -29,6 +30,18 @@
OneToOneFieldInstance,
)

if sys.version_info >= (3, 14):

def union_annotation(x: str, y: str) -> str:
return f"{x} | {y}"
else:

def union_annotation(x: str, y: str) -> str:
return f"Union[{x}, {y}]"


UNION_DICT_LIST = union_annotation("dict", "list")


class TestDescribeModels(test.TestCase):
def test_describe_models_all_serializable(self):
Expand Down Expand Up @@ -1366,7 +1379,7 @@ def test_describe_model_json(self):
"oracle": "NCLOB",
"postgres": "JSONB",
},
"python_type": "Union[dict, list]",
"python_type": UNION_DICT_LIST,
"generated": False,
"nullable": False,
"unique": False,
Expand All @@ -1386,7 +1399,7 @@ def test_describe_model_json(self):
"oracle": "NCLOB",
"postgres": "JSONB",
},
"python_type": "Union[dict, list]",
"python_type": UNION_DICT_LIST,
"generated": False,
"nullable": True,
"unique": False,
Expand All @@ -1406,7 +1419,7 @@ def test_describe_model_json(self):
"oracle": "NCLOB",
"postgres": "JSONB",
},
"python_type": "Union[dict, list]",
"python_type": UNION_DICT_LIST,
"generated": False,
"nullable": False,
"unique": False,
Expand All @@ -1426,7 +1439,7 @@ def test_describe_model_json(self):
"oracle": "NCLOB",
"postgres": "JSONB",
},
"python_type": "Union[dict, list]",
"python_type": UNION_DICT_LIST,
"generated": False,
"nullable": True,
"unique": False,
Expand Down
16 changes: 10 additions & 6 deletions tortoise/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import asyncio
import importlib
import json
import logging
Expand All @@ -12,6 +11,7 @@
from types import ModuleType
from typing import Any, cast

from anyio import from_thread
from pypika_tortoise import Query, Table

from tortoise.backends.base.client import BaseDBAsyncClient
Expand Down Expand Up @@ -637,11 +637,15 @@ async def do_stuff():

run_async(do_stuff())
"""
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(coro)
finally:
loop.run_until_complete(connections.close_all(discard=True))

async def main() -> None:
try:
await coro
finally:
await connections.close_all(discard=True)

with from_thread.start_blocking_portal() as portal:
portal.call(main)


__version__ = "0.25.1"
Expand Down
6 changes: 4 additions & 2 deletions tortoise/contrib/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
import sys
import typing
import unittest
from asyncio.events import AbstractEventLoop
from collections.abc import Callable, Coroutine, Iterable
from functools import partial, wraps
from types import ModuleType
from typing import Any, TypeVar, Union, cast
from typing import TYPE_CHECKING, Any, TypeVar, Union, cast
from unittest import SkipTest, expectedFailure, skip, skipIf, skipUnless

from tortoise import Model, Tortoise, connections
Expand All @@ -22,6 +21,9 @@
else:
from typing_extensions import ParamSpec

if TYPE_CHECKING:
from asyncio.events import AbstractEventLoop


__all__ = (
"MEMORY_SQLITE",
Expand Down
Loading