From 20106e64c9bff5f65a4f1c5780609a4e537503fc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 2 Aug 2026 12:24:19 +0000 Subject: [PATCH 1/2] fix(deps-dev): bump ruff from 0.15.16 to 0.16.0 Bumps [ruff](https://github.com/astral-sh/ruff) from 0.15.16 to 0.16.0. - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](https://github.com/astral-sh/ruff/compare/0.15.16...0.16.0) --- updated-dependencies: - dependency-name: ruff dependency-version: 0.15.22 dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- uv.lock | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/uv.lock b/uv.lock index 6c20371..985ae07 100644 --- a/uv.lock +++ b/uv.lock @@ -1369,27 +1369,27 @@ wheels = [ [[package]] name = "ruff" -version = "0.15.16" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/a6/bd/5f7ec371001337d8fa61701c186ff8b613ecac1651848c5950f4c4d5f2e9/ruff-0.15.16.tar.gz", hash = "sha256:d05e78d38c78caf020b03789e25106c93017db5a0cb6e2819885018c61343b78", size = 4714267, upload-time = "2026-06-04T16:33:09.974Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/0c/42/53ef1c3953f157956db9bf7861e3bc50b9b887ce93300aa48cdba8336fe6/ruff-0.15.16-py3-none-linux_armv6l.whl", hash = "sha256:6ac3c0b3969cc6cf6b158c4e2f8f682acb58e7d700d8a44b65ecdc72d66ab0b2", size = 10709025, upload-time = "2026-06-04T16:32:51.935Z" }, - { url = "https://files.pythonhosted.org/packages/93/9a/a79159346f19134a956607754e57d8d128f7a4c00f4ad2f7514d224c172c/ruff-0.15.16-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:197c207ed75ffba54a0dec23db4aa939a27a3053073e085e0042433cbdc58e4a", size = 11063550, upload-time = "2026-06-04T16:32:42.24Z" }, - { url = "https://files.pythonhosted.org/packages/bc/72/3ce2ac000a5299ec238e01f51397b3b653c93b077d9b1bfe8715bb895f20/ruff-0.15.16-py3-none-macosx_11_0_arm64.whl", hash = "sha256:3a39fec45ab316cc23e7558f23fea4a70403ddb5648ea9a4a3854a16973d0071", size = 10421345, upload-time = "2026-06-04T16:32:37.251Z" }, - { url = "https://files.pythonhosted.org/packages/b0/c2/cc7fad3ec9169373f5b6a18f1917b91080feec40c3f9658334a1d28e2f03/ruff-0.15.16-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ba93191d79003116b95128c9d306e045200fdbd0bccb782b110f3cd1d4abc5cf", size = 10757217, upload-time = "2026-06-04T16:32:54.722Z" }, - { url = "https://files.pythonhosted.org/packages/69/d2/3474009eaa0a65b31fa7152a2fad5e2f050c640ceb1e6b02ee6922e94c82/ruff-0.15.16-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:c6ee4b90520630120ef032aa5cc10db483852dff950e78b1d717e2993a61ac8d", size = 10507035, upload-time = "2026-06-04T16:33:05.343Z" }, - { url = "https://files.pythonhosted.org/packages/ca/81/b7ae6ccbd11f0c8dc3d5d67fc4be9b57ff57ca86ba56152021378e1277f2/ruff-0.15.16-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4e4215bc938bc3c8215c1472c1aa437e310fee20cd427335fec9d7e609563628", size = 11255291, upload-time = "2026-06-04T16:32:49.49Z" }, - { url = "https://files.pythonhosted.org/packages/d9/e1/46e526f1a7cc90857ce6ddf25fbb77eb6568651ac38d71b033af07076dd5/ruff-0.15.16-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:7c8d26be963b090f10e29abc8b3e74a2a321f6fa34e02424e30b5af89350ecbb", size = 12124922, upload-time = "2026-06-04T16:33:07.821Z" }, - { url = "https://files.pythonhosted.org/packages/1a/da/5c791b088b596b24d0deb967fa28ae02ad751a140c0b9ea81c5ab915d6c0/ruff-0.15.16-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:f198cf4123602a2280ed46c307bcbafe41758d6fee5b456b6b6058ca1514b3b4", size = 11332186, upload-time = "2026-06-04T16:33:02.971Z" }, - { url = "https://files.pythonhosted.org/packages/72/11/5da87abe20047c8962361473923ebb2f62b595250126aadfad8c20649c1e/ruff-0.15.16-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bb27515fa6240fb586ae82b901a59e67d24acff86f2190b433dc542fe0435aeb", size = 11373541, upload-time = "2026-06-04T16:32:47.007Z" }, - { url = "https://files.pythonhosted.org/packages/fe/2a/8554754c23a854ae3fd6b507e36ad61ddb121e298c6d5d617dec94ed0f14/ruff-0.15.16-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:a267c46ba1593fc26b8eecbea050b39d40c0b6bb7781ee11c90a02cd10032951", size = 11353014, upload-time = "2026-06-04T16:32:34.795Z" }, - { url = "https://files.pythonhosted.org/packages/62/25/62ea41529ec89f742ea3fed9cb1059c72877ec7cf9b9e99ac9cf3294d1d9/ruff-0.15.16-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:528c68f39a91498a8d50e91ff5985df3d105782bab49cc378e73ac26bff083e8", size = 10737467, upload-time = "2026-06-04T16:32:26.348Z" }, - { url = "https://files.pythonhosted.org/packages/90/17/334d3ad9de4d40f9dd58fdd09e35ce64553bb501e2f19a839e2fb6be14fc/ruff-0.15.16-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:7ed55c58950df60589a9a7a5d2f8fa5f54ebd287163be805adfe6ee95a9de123", size = 10521910, upload-time = "2026-06-04T16:32:32.54Z" }, - { url = "https://files.pythonhosted.org/packages/4d/bd/3ac7c6ae77a885c1004b3dda2446ea401768d24f851c14b4ad4b24f6639c/ruff-0.15.16-py3-none-musllinux_1_2_i686.whl", hash = "sha256:d482feaf51512b50f9790ceb417a56a61dd1e9d9bf967662b9ed27c01b34f53a", size = 10979190, upload-time = "2026-06-04T16:32:57.492Z" }, - { url = "https://files.pythonhosted.org/packages/33/d7/609546e6a413c3f216fbf2a50c928f97c80939154f6a0503114094a86191/ruff-0.15.16-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:1e15bc8c94513dae2a40cc9ef07c94fdd4ecc9e29dabebeebe170f952322c9e3", size = 11477014, upload-time = "2026-06-04T16:32:44.687Z" }, - { url = "https://files.pythonhosted.org/packages/74/0d/f2cd247ad32633a5c36e97141a2c21b11c6279f7957bc2ff360b1e08fddd/ruff-0.15.16-py3-none-win32.whl", hash = "sha256:580378f7bd4aa25f72e74aa54948a9622f142b1e509521dd10902e886681cc1e", size = 10735541, upload-time = "2026-06-04T16:32:30.145Z" }, - { url = "https://files.pythonhosted.org/packages/8b/9e/02e845ef151b1dee585e55c4739f8e1734ae1d9f1221dff65761c162208b/ruff-0.15.16-py3-none-win_amd64.whl", hash = "sha256:408256017284eddf98fff77b29aa4fb30f586042d535b2d9befc6512f400aaec", size = 11843403, upload-time = "2026-06-04T16:32:39.76Z" }, - { url = "https://files.pythonhosted.org/packages/15/19/016553f86f207450aebebc2b2b5088d086b901cc8186c02ac4284db3bd88/ruff-0.15.16-py3-none-win_arm64.whl", hash = "sha256:8cd61783afb39638a7133ef0d2dfb1e91277593962f81b5a8423eb0b888a6121", size = 11134555, upload-time = "2026-06-04T16:33:00.136Z" }, +version = "0.16.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/4d/94/1e5e4967626faf12fa56999cd6222dff6992ceb086ad7945756baf70c7a7/ruff-0.16.0.tar.gz", hash = "sha256:e460aafd5495ec89efaa6ced2e4a9a581116451e1c88b9d37ef497e0f8e93982", size = 4790557, upload-time = "2026-07-23T19:11:30.981Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/4b/81/1c8818fee7ce1a04cd7d1b3172e0a8f8e4f1dc4feb7fc390e16daa8af323/ruff-0.16.0-py3-none-linux_armv6l.whl", hash = "sha256:e5115729eb08c585e5121978ba5d5b60caeae394ce21b9fb5e6cd33a1c6c9b1e", size = 10754633, upload-time = "2026-07-23T19:10:46.415Z" }, + { url = "https://files.pythonhosted.org/packages/23/df/beaf59c09d68db84304d555f188b276a77132a5d5b0b67a5c762aa143628/ruff-0.16.0-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:3c954b1d580bfa035b41654f7858cc7e71d5fc3ac5b723dd62bd9133830ed522", size = 10969164, upload-time = "2026-07-23T19:10:50.271Z" }, + { url = "https://files.pythonhosted.org/packages/42/ce/741cd197496a1abbf51352710fd15ed995d2a2be87189c1da26a450d6e83/ruff-0.16.0-py3-none-macosx_11_0_arm64.whl", hash = "sha256:e01c21d10eb1b29f47b7454e1f4056db9a3f0260c646aa88457c610291db9f81", size = 10488846, upload-time = "2026-07-23T19:10:52.639Z" }, + { url = "https://files.pythonhosted.org/packages/52/2a/a2db8e88cade358f5cdcb05674a917751074109315d014eb6352d9a893f7/ruff-0.16.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6e364e5ed22ed8dc05082fd78e35308618260907ac2d3c1d637b2e682415b6c9", size = 10889729, upload-time = "2026-07-23T19:10:54.89Z" }, + { url = "https://files.pythonhosted.org/packages/42/65/62a771694ebd63029dc953e27dbad40e1588bd4860ff9fe881018fddaa49/ruff-0.16.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:d327b8fc113a1d4421a04f3839d3752057c8dd1ee320223a6f3f52d04ada462a", size = 10568275, upload-time = "2026-07-23T19:10:56.993Z" }, + { url = "https://files.pythonhosted.org/packages/3f/e2/ced249fe8af5f086c5c58cc21cc3356d50f32f7401c5df87050c999620a7/ruff-0.16.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a9b50c55e263103586b3dcf5f73d479eb8cb5fdb6098fec59a62891dab653717", size = 11385112, upload-time = "2026-07-23T19:10:59.615Z" }, + { url = "https://files.pythonhosted.org/packages/87/0b/05154977a8fd69eeb6c103271f55403bfd8711f5c0f8ed07489d95a504e7/ruff-0.16.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:0ff4a79ce3ec0172f3241943835de1c4cb4e2dcd07f0f8c2d02603dbbbee4b17", size = 12207008, upload-time = "2026-07-23T19:11:02.154Z" }, + { url = "https://files.pythonhosted.org/packages/fb/29/98225831a3a1eab0e02f4acc6ca6559a98611dcc68b6965ff4b7234627c1/ruff-0.16.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:e95c448fca1fb2a18372a9440926c5a6ee789639bb975c72e7ae6d0b04218ab4", size = 11650842, upload-time = "2026-07-23T19:11:04.557Z" }, + { url = "https://files.pythonhosted.org/packages/91/66/6bd3cf90500653d55dc0ffc8507aa8300bd49d0214b2e8cb4d3fef2943ba/ruff-0.16.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4f11a8d11010301d0a398a2fdef67691feca7294da6aef55e2150e8fa2cd520b", size = 11400718, upload-time = "2026-07-23T19:11:09.233Z" }, + { url = "https://files.pythonhosted.org/packages/8e/a2/a54eb4eae05d66364050a5d3b8a9c5ef88196531b3cbe7109d873f87f819/ruff-0.16.0-py3-none-manylinux_2_31_riscv64.whl", hash = "sha256:48044c678e9cb8698246c99b14aaccfa6601dea7379eb48a6f8f73f7a6d86cd0", size = 11426177, upload-time = "2026-07-23T19:11:11.994Z" }, + { url = "https://files.pythonhosted.org/packages/1a/be/16e3eea4b2a478a496919f5e36f17c4559e54620bd3bbac5d6affa068006/ruff-0.16.0-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:7aa0959bad8eb8bef50340154fc9b58678dae31fa4293afa38b44b6e552c0213", size = 10856126, upload-time = "2026-07-23T19:11:14.221Z" }, + { url = "https://files.pythonhosted.org/packages/a2/84/252eb8b868a16eec7257c14f504f77537e734b2d69c762e639e588e304a3/ruff-0.16.0-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:28ea2b7df8ebf7f9da6b7d47b230ab48f387c0a29be3b474c4d0740e197bb9af", size = 10571208, upload-time = "2026-07-23T19:11:16.378Z" }, + { url = "https://files.pythonhosted.org/packages/21/09/817a482f542f7570cbb4554b26e896610c7114f539b1d9e2d2145bf6bef6/ruff-0.16.0-py3-none-musllinux_1_2_i686.whl", hash = "sha256:33a3dfac8c35f81498dea9181bccc2f4c4bc8f1521a1dd9406e77643e0f0fb09", size = 11063329, upload-time = "2026-07-23T19:11:19.173Z" }, + { url = "https://files.pythonhosted.org/packages/2e/23/9403c180ca1cb9b1f7335f5c3e5305c09d49ea5b345196682a36028bde4a/ruff-0.16.0-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:a5237a0bda500d30d81b8e07a6973a5cbc772864cbf746ae2f4e8a2e01c9f4ed", size = 11489751, upload-time = "2026-07-23T19:11:21.74Z" }, + { url = "https://files.pythonhosted.org/packages/b2/1d/1b2ef7bcde851c78d7f17f1cca13fd6dc695fc4b3d6197941e72cae5b132/ruff-0.16.0-py3-none-win32.whl", hash = "sha256:7fab76fa065c873f41ff744347c6e77bcc3dfec4bcc754dc26b63d23c0f7f5fb", size = 10785885, upload-time = "2026-07-23T19:11:23.947Z" }, + { url = "https://files.pythonhosted.org/packages/b2/a3/d5e4ef7a56be3f928ffb90b94c25ba7d3cb9c7fe0736aeaaedf361770712/ruff-0.16.0-py3-none-win_amd64.whl", hash = "sha256:429c117f022bf481fabd9d551e7a3952b24c65e6ef44337ea09d90bebef14472", size = 11923141, upload-time = "2026-07-23T19:11:26.409Z" }, + { url = "https://files.pythonhosted.org/packages/cb/9a/8415f2657cbe200f41a4531ccededf135505a92d4a012229121f885b26f9/ruff-0.16.0-py3-none-win_arm64.whl", hash = "sha256:14296fedcd2705c77ab8235439278bbb38f285cf7da5528b00b3e330c3d4872d", size = 11273407, upload-time = "2026-07-23T19:11:28.705Z" }, ] [[package]] From 11cb3c084743d982a41dc67c3d138f9bbe0ab86a Mon Sep 17 00:00:00 2001 From: Hadrien David Date: Sun, 2 Aug 2026 08:38:50 -0400 Subject: [PATCH 2/2] fix: satisfy Ruff 0.16 checks --- src/fastsqla.py | 20 +++++++++++++++----- tests/integration/conftest.py | 4 ++-- tests/integration/test_pagination.py | 4 +++- tests/integration/test_session_dependency.py | 1 - tests/integration/test_sqlmodel.py | 6 +++--- tests/unit/test_lifespan.py | 10 +++++----- tests/unit/test_open_session.py | 14 ++++++++------ 7 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/fastsqla.py b/src/fastsqla.py index 56461f5..dd84036 100644 --- a/src/fastsqla.py +++ b/src/fastsqla.py @@ -2,7 +2,7 @@ import os from collections.abc import AsyncGenerator, Awaitable, Callable, Iterable from contextlib import _AsyncGeneratorContextManager, asynccontextmanager -from typing import Annotated, Generic, TypedDict, TypeVar +from typing import Annotated, TypedDict, TypeVar from fastapi import Depends as BaseDepends from fastapi import FastAPI, Query @@ -31,6 +31,7 @@ "Base", "Collection", "Item", + "MissingConfigurationError", "Page", "Paginate", "PaginateType", @@ -88,6 +89,10 @@ class State(TypedDict): fastsqla_engine: AsyncEngine +class MissingConfigurationError(RuntimeError): + """Raised when a required SQLAlchemy setting is missing.""" + + def new_lifespan( url: str | None = None, **kw ) -> Callable[[FastAPI | None], _AsyncGeneratorContextManager[State, None]]: @@ -112,6 +117,9 @@ def new_lifespan( Args: url (str): Database url. kw (dict): Configuration parameters as expected by [`sqlalchemy.ext.asyncio.create_async_engine`][sqlalchemy.ext.asyncio.create_async_engine] + + Raises: + MissingConfigurationError: If a required SQLAlchemy setting is missing. """ has_config = url is not None @@ -120,7 +128,7 @@ def new_lifespan( async def lifespan(app: FastAPI | None) -> AsyncGenerator[State, None]: if has_config: prefix = "" - sqla_config = {**kw, **{"url": url}} + sqla_config = {**kw, "url": url} else: prefix = "sqlalchemy_" @@ -130,7 +138,9 @@ async def lifespan(app: FastAPI | None) -> AsyncGenerator[State, None]: engine = async_engine_from_config(sqla_config, prefix=prefix) except KeyError as exc: - raise Exception(f"Missing {prefix}{exc.args[0]} in environ.") from exc + raise MissingConfigurationError( + f"Missing {prefix}{exc.args[0]} in environ." + ) from exc async with engine.begin() as conn: await conn.run_sync(Base.prepare) @@ -330,11 +340,11 @@ class Meta(BaseModel): T = TypeVar("T") -class Item(BaseModel, Generic[T]): +class Item[T](BaseModel): data: T -class Collection(BaseModel, Generic[T]): +class Collection[T](BaseModel): data: list[T] diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 50707e6..f656955 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -1,7 +1,7 @@ from asgi_lifespan import LifespanManager -from httpx import AsyncClient, ASGITransport -from pytest import fixture from fastapi import FastAPI +from httpx import ASGITransport, AsyncClient +from pytest import fixture @fixture diff --git a/tests/integration/test_pagination.py b/tests/integration/test_pagination.py index abbfe50..89b143a 100644 --- a/tests/integration/test_pagination.py +++ b/tests/integration/test_pagination.py @@ -1,4 +1,5 @@ from typing import Annotated, cast + from fastapi import Depends from pydantic import EmailStr from pytest import fixture @@ -57,10 +58,11 @@ async def setup_tear_down(engine, faker): @fixture def app(app): - from fastsqla import Base, Page, Paginate, PaginateType, Session, new_pagination from pydantic import BaseModel from sqlalchemy.orm import Mapped, mapped_column + from fastsqla import Base, Page, Paginate, PaginateType, Session, new_pagination + class User(Base): __tablename__ = "user" id: Mapped[int] = mapped_column(primary_key=True) diff --git a/tests/integration/test_session_dependency.py b/tests/integration/test_session_dependency.py index d3431e1..fbf5cf1 100644 --- a/tests/integration/test_session_dependency.py +++ b/tests/integration/test_session_dependency.py @@ -48,7 +48,6 @@ async def get_session(session: Session): @app.post("/users", response_model=Item[UserModel], status_code=HTTPStatus.CREATED) async def create_user(user_in: UserIn, session: Session): user = User(**user_in.model_dump()) - user_in.model_dump session.add(user) try: await session.flush() diff --git a/tests/integration/test_sqlmodel.py b/tests/integration/test_sqlmodel.py index 7fb8c30..9c66c50 100644 --- a/tests/integration/test_sqlmodel.py +++ b/tests/integration/test_sqlmodel.py @@ -6,7 +6,6 @@ from sqlalchemy.exc import IntegrityError from sqlalchemy.ext.automap import automap_base - pytestmark = mark.require_sqlmodel @@ -49,7 +48,7 @@ async def setup_tear_down(engine, heros_data): stmt = insert(Hero).values( [ - dict(name=name, secret_identity=secret_identity, age=age) + {"name": name, "secret_identity": secret_identity, "age": age} for name, secret_identity, age in heros_data ] ) @@ -61,9 +60,10 @@ async def setup_tear_down(engine, heros_data): @fixture async def app(setup_tear_down, app): - from fastsqla import Item, Page, Paginate, Session from sqlmodel import Field, SQLModel + from fastsqla import Item, Page, Paginate, Session + class Hero(SQLModel, table=True): __table_args__ = {"extend_existing": True} id: int | None = Field(default=None, primary_key=True) diff --git a/tests/unit/test_lifespan.py b/tests/unit/test_lifespan.py index d57a6e0..684713c 100644 --- a/tests/unit/test_lifespan.py +++ b/tests/unit/test_lifespan.py @@ -1,5 +1,5 @@ from fastapi import FastAPI -from pytest import raises, fixture +from pytest import fixture, raises _app = FastAPI() @@ -31,15 +31,15 @@ async def test_it_binds_an_sqla_engine_to_sessionmaker(environ, app): async def test_it_fails_on_a_missing_sqlalchemy_url(monkeypatch, app): - from fastsqla import lifespan + from fastsqla import MissingConfigurationError, lifespan monkeypatch.delenv("SQLALCHEMY_URL", raising=False) - with raises(Exception) as raise_info: + with raises( + MissingConfigurationError, match=r"Missing sqlalchemy_url in environ\." + ): async with lifespan(app): pass - assert raise_info.value.args[0] == "Missing sqlalchemy_url in environ." - async def test_it_fails_on_not_async_engine(monkeypatch, app): from fastsqla import lifespan diff --git a/tests/unit/test_open_session.py b/tests/unit/test_open_session.py index 74bf53f..11922bc 100644 --- a/tests/unit/test_open_session.py +++ b/tests/unit/test_open_session.py @@ -4,6 +4,10 @@ from sqlalchemy import text +class SimulatedError(RuntimeError): + pass + + @fixture def tablename(request): return request.node.name @@ -38,22 +42,20 @@ async def test_it_re_raises_when_committing_fails(): with patch("fastsqla.SessionFactory") as SessionFactory: session = AsyncMock() - session.commit.side_effect = Exception("Simulating a failure.") + session.commit.side_effect = SimulatedError("Simulating a failure.") SessionFactory.return_value = session - with raises(Exception) as raise_info: + with raises(SimulatedError, match=r"Simulating a failure\."): async with open_session(): pass - assert "Simulating a failure." in raise_info.value.args[0] - async def test_it_rollback_on_failure(engine, tablename): from fastsqla import open_session - with raises(Exception): + with raises(SimulatedError, match=r"Simulating a failure\."): async with open_session() as session: await session.execute(text(f"insert into {tablename} values ('OK')")) - raise Exception("Simulating a failure.") + raise SimulatedError("Simulating a failure.") async with engine.connect() as conn: res = await conn.execute(text(f"select * from {tablename}"))