File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
tests/integrations/asyncpg Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,24 @@ def _get_db_name():
6060
6161@pytest_asyncio .fixture (autouse = True )
6262async def _clean_pg ():
63+ # Create the test database if it doesn't exist
64+ try :
65+ default_conn = await connect (PG_CONNECTION_URI )
66+ try :
67+ # Check if database exists, create if not
68+ result = await default_conn .fetchval (
69+ "SELECT 1 FROM pg_database WHERE datname = $1" , PG_NAME
70+ )
71+ if not result :
72+ await default_conn .execute (f'CREATE DATABASE "{ PG_NAME } "' )
73+ finally :
74+ await default_conn .close ()
75+ except Exception :
76+ # If we can't connect to default postgres db, assume our test db already exists
77+ # or that we're connecting to the same database (PG_NAME == PG_NAME_BASE)
78+ pass
79+
80+ # Now connect to our test database and set up the table
6381 conn = await connect (PG_CONNECTION_URI )
6482 await conn .execute ("DROP TABLE IF EXISTS users" )
6583 await conn .execute (
You can’t perform that action at this time.
0 commit comments