33import httpx
44from asgi_lifespan import LifespanManager
55from fastapi import FastAPI
6- from pytest import fixture , mark
6+ from pytest import fixture , mark , raises
77from sqlalchemy import text
88
99
@@ -16,7 +16,7 @@ def case_sensitive_environ(environ, request):
1616 yield values
1717
1818
19- @mark .dont_patch_engine_from_config
19+ @mark .dont_patch_engines
2020def test_startup (case_sensitive_environ ):
2121 from fastapi_sqla import _Session , startup
2222
@@ -48,3 +48,26 @@ def now():
4848 res = await client .get ("/one" )
4949
5050 assert res .json () == 1
51+
52+
53+ @mark .dont_patch_engines
54+ def test_startup_fail_on_bad_sqlalchemy_url (monkeypatch ):
55+ from fastapi_sqla import startup
56+
57+ monkeypatch .setenv ("sqlalchemy_url" , "postgresql://postgres@localhost/notexisting" )
58+
59+ with raises (Exception ):
60+ startup ()
61+
62+
63+ @mark .asyncio
64+ @mark .dont_patch_engines
65+ async def test_async_startup_fail_on_bad_async_sqlalchemy_url (monkeypatch ):
66+ from fastapi_sqla import asyncio_support
67+
68+ monkeypatch .setenv (
69+ "async_sqlalchemy_url" , "postgresql+asyncpg://postgres@localhost/notexisting"
70+ )
71+
72+ with raises (Exception ):
73+ await asyncio_support .startup ()
0 commit comments