Skip to content

Commit f4dd6c7

Browse files
committed
cleanup
1 parent b4773c6 commit f4dd6c7

File tree

1 file changed

+13
-39
lines changed

1 file changed

+13
-39
lines changed

tests/integrations/asyncpg/test_asyncpg.py

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,20 @@
1111

1212
import os
1313
import threading
14+
import datetime
15+
from contextlib import contextmanager
16+
from unittest import mock
17+
18+
import asyncpg
19+
import pytest
20+
import pytest_asyncio
21+
from asyncpg import connect, Connection
1422

23+
from sentry_sdk import capture_message, start_transaction
24+
from sentry_sdk.integrations.asyncpg import AsyncPGIntegration
25+
from sentry_sdk.consts import SPANDATA
26+
from sentry_sdk.tracing_utils import record_sql_queries
27+
from tests.conftest import ApproxDict
1528

1629
PG_HOST = os.getenv("SENTRY_PYTHON_TEST_POSTGRES_HOST", "localhost")
1730
PG_PORT = int(os.getenv("SENTRY_PYTHON_TEST_POSTGRES_PORT", "5432"))
@@ -28,22 +41,6 @@ def _get_db_name():
2841

2942
PG_NAME = _get_db_name()
3043

31-
import datetime
32-
from contextlib import contextmanager
33-
from unittest import mock
34-
35-
import asyncpg
36-
import pytest
37-
import pytest_asyncio
38-
from asyncpg import connect, Connection
39-
40-
from sentry_sdk import capture_message, start_transaction
41-
from sentry_sdk.integrations.asyncpg import AsyncPGIntegration
42-
from sentry_sdk.consts import SPANDATA
43-
from sentry_sdk.tracing_utils import record_sql_queries
44-
from tests.conftest import ApproxDict
45-
46-
4744
PG_CONNECTION_URI = "postgresql://{}:{}@{}/{}".format(
4845
PG_USER, PG_PASSWORD, PG_HOST, PG_NAME
4946
)
@@ -65,29 +62,6 @@ def _get_db_name():
6562

6663
@pytest_asyncio.fixture(autouse=True)
6764
async def _clean_pg():
68-
# Connect to the default postgres database to create our test database
69-
default_conn_uri = "postgresql://{}:{}@{}/{}".format(
70-
PG_USER, PG_PASSWORD, PG_HOST, PG_NAME_BASE
71-
)
72-
73-
# Create the test database if it doesn't exist
74-
try:
75-
default_conn = await connect(default_conn_uri)
76-
try:
77-
# Check if database exists, create if not
78-
result = await default_conn.fetchval(
79-
"SELECT 1 FROM pg_database WHERE datname = $1", PG_NAME
80-
)
81-
if not result:
82-
await default_conn.execute(f'CREATE DATABASE "{PG_NAME}"')
83-
finally:
84-
await default_conn.close()
85-
except Exception:
86-
# If we can't connect to default postgres db, assume our test db already exists
87-
# or that we're connecting to the same database (PG_NAME == PG_NAME_BASE)
88-
pass
89-
90-
# Now connect to our test database and set up the table
9165
conn = await connect(PG_CONNECTION_URI)
9266
await conn.execute("DROP TABLE IF EXISTS users")
9367
await conn.execute(

0 commit comments

Comments
 (0)