From 7cc0ca038af21012a3c74c8dd7b0c640a8f97b25 Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Fri, 25 Sep 2026 16:02:19 +0300 Subject: [PATCH] test: accept sqlalchemy 2.1 wrapping the factory's TargetServerAttributeNotMatched --- tests/test_connection_factory.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_connection_factory.py b/tests/test_connection_factory.py index 9f77e1c..ab4bbbe 100644 --- a/tests/test_connection_factory.py +++ b/tests/test_connection_factory.py @@ -6,6 +6,7 @@ import pytest import sqlalchemy from asyncpg.connect_utils import SessionAttribute +from sqlalchemy import exc as sa_exc from sqlalchemy.ext import asyncio as sa_async from db_retry.connections import ConnectionPlan, build_connection_factory, build_connection_plan @@ -49,10 +50,13 @@ async def test_connection_factory_failure_several_hosts( url=url, echo=True, echo_pool=True, async_creator=build_connection_factory(url=url, timeout=1.0) ) try: - with pytest.raises(asyncpg.TargetServerAttributeNotMatched): + with pytest.raises((asyncpg.TargetServerAttributeNotMatched, sa_exc.InternalError)) as exc_info: await engine.connect().__aenter__() finally: await engine.dispose() + raised = exc_info.value + root = raised.orig.__cause__ if isinstance(raised, sa_exc.InternalError) and raised.orig is not None else raised + assert isinstance(root, asyncpg.TargetServerAttributeNotMatched) async def test_connection_factory_failure_and_success(monkeypatch: pytest.MonkeyPatch) -> None: