Skip to content

Commit 0b59394

Browse files
committed
.
1 parent 0de8099 commit 0b59394

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

tests/integrations/asyncpg/test_asyncpg.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,18 @@ def _get_db_name():
6161
@pytest_asyncio.fixture(autouse=True)
6262
async def _clean_pg():
6363
# Create the test database if it doesn't exist
64+
default_conn = await connect(
65+
"postgresql://{}:{}@{}".format(PG_USER, PG_PASSWORD, PG_HOST)
66+
)
6467
try:
65-
default_conn = await connect(
66-
"postgresql://{}:{}@{}".format(PG_USER, PG_PASSWORD, PG_HOST)
68+
# Check if database exists, create if not
69+
result = await default_conn.fetchval(
70+
"SELECT 1 FROM pg_database WHERE datname = $1", PG_NAME
6771
)
68-
try:
69-
# Check if database exists, create if not
70-
result = await default_conn.fetchval(
71-
"SELECT 1 FROM pg_database WHERE datname = $1", PG_NAME
72-
)
73-
if not result:
74-
await default_conn.execute(f'CREATE DATABASE "{PG_NAME}"')
75-
finally:
76-
await default_conn.close()
77-
except Exception:
78-
# If we can't connect to default postgres db, assume our test db already exists
79-
# or that we're connecting to the same database (PG_NAME == PG_NAME_BASE)
80-
pass
72+
if not result:
73+
await default_conn.execute(f'CREATE DATABASE "{PG_NAME}"')
74+
finally:
75+
await default_conn.close()
8176

8277
# Now connect to our test database and set up the table
8378
conn = await connect(PG_CONNECTION_URI)

0 commit comments

Comments
 (0)