@@ -83,7 +83,8 @@ def _make(is_async=True) -> Awaitable[Engine] | sa.engine.base.Engine:
8383
8484
8585@pytest .fixture
86- def make_asyncio_engine (postgres_service : str ) -> Callable [[bool ], AsyncEngine ]:
86+ def make_asyncpg_engine (postgres_service : str ) -> Callable [[bool ], AsyncEngine ]:
87+ # NOTE: users is responsible of `await engine.dispose()`
8788 dsn = postgres_service .replace ("postgresql://" , "postgresql+asyncpg://" )
8889 minsize = 1
8990 maxsize = 50
@@ -131,6 +132,11 @@ def pg_sa_engine(
131132) -> Iterator [sa .engine .Engine ]:
132133 """
133134 Runs migration to create tables and return a sqlalchemy engine
135+
136+ NOTE: use this fixture to ensure pg db:
137+ - up,
138+ - responsive,
139+ - init (w/ tables) and/or migrated
134140 """
135141 # NOTE: Using migration to upgrade/downgrade is not
136142 # such a great idea since these tests are used while developing
@@ -189,6 +195,24 @@ async def connection(aiopg_engine: Engine) -> AsyncIterator[SAConnection]:
189195 yield _conn
190196
191197
198+ @pytest .fixture
199+ async def asyncpg_engine (
200+ is_pdb_enabled : bool ,
201+ pg_sa_engine : sa .engine .Engine ,
202+ make_asyncpg_engine : Callable [[bool ], AsyncEngine ],
203+ ) -> AsyncIterator [AsyncEngine ]:
204+
205+ assert (
206+ pg_sa_engine
207+ ), "Ensures pg db up, responsive, init (w/ tables) and/or migrated"
208+
209+ _apg_engine = make_asyncpg_engine (is_pdb_enabled )
210+
211+ yield _apg_engine
212+
213+ await _apg_engine .dispose ()
214+
215+
192216#
193217# FACTORY FIXTURES
194218#
0 commit comments