Skip to content

Commit edd9fd0

Browse files
committed
Testing: Streamline table reset procedure using SA's drop_all_tables
1 parent 18c52fa commit edd9fd0

File tree

2 files changed

+7
-16
lines changed

2 files changed

+7
-16
lines changed

tests/conftest.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import pytest
22
import sqlalchemy as sa
3+
from sqlalchemy.testing.util import drop_all_tables
34

45

56
@pytest.fixture
67
def engine():
78
engine = sa.create_engine("crate://")
8-
with engine.connect() as conn:
9-
# Clean up stale "read-only" mode states.
10-
try:
11-
conn.execute(sa.text('ALTER TABLE testdrive.foo RESET ("blocks.write");'))
12-
except Exception: # noqa: S110
13-
pass
14-
conn.execute(sa.text("DROP TABLE IF EXISTS testdrive.foo"))
15-
conn.execute(sa.text("DROP TABLE IF EXISTS testdrive.foo_alter_tmp"))
9+
with engine.connect() as connection:
10+
inspector = sa.inspect(connection)
11+
drop_all_tables(engine, inspector, schema="testdrive")
1612
yield engine
1713
engine.dispose()

tests/test_integration.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import pytest
88
import sqlalchemy as sa
99
from sqlalchemy.sql.type_api import UserDefinedType
10+
from sqlalchemy.testing.util import drop_all_tables
1011
from sqlalchemy_cratedb import ObjectType
1112

1213
pytestmark = pytest.mark.sdktester
@@ -22,14 +23,8 @@ def run(command: str, background: bool = False):
2223
@pytest.fixture(autouse=True)
2324
def reset_tables(engine):
2425
with engine.connect() as connection:
25-
connection.execute(sa.text("DROP TABLE IF EXISTS tester.all_types"))
26-
connection.execute(sa.text("DROP TABLE IF EXISTS tester.all_types_alter_tmp"))
27-
connection.execute(sa.text("DROP TABLE IF EXISTS tester.campaign"))
28-
connection.execute(sa.text("DROP TABLE IF EXISTS tester.campaign_alter_tmp"))
29-
connection.execute(sa.text("DROP TABLE IF EXISTS tester.composite_table"))
30-
connection.execute(sa.text("DROP TABLE IF EXISTS tester.composite_table_alter_tmp"))
31-
connection.execute(sa.text("DROP TABLE IF EXISTS tester.transaction"))
32-
connection.execute(sa.text("DROP TABLE IF EXISTS tester.transaction_alter_tmp"))
26+
inspector = sa.inspect(connection)
27+
drop_all_tables(engine, inspector, schema="tester")
3328

3429

3530
@pytest.fixture()

0 commit comments

Comments
 (0)