Skip to content

Commit f150405

Browse files
committed
deleting and creating db for each module
1 parent d949051 commit f150405

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

scripts/run_group.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949

5050

5151
def create_databases():
52-
"""Creates the required test databases if they don't already exist."""
53-
print("--- Creating test databases ---")
52+
"""Drops and recreates the required test databases to ensure they are empty."""
53+
print("--- Resetting test databases ---")
5454
password = os.environ.get("SINGLESTORE_PASSWORD", "")
5555
databases_to_create = ["test_django_db", "test_django_db_other"]
5656

@@ -60,11 +60,12 @@ def create_databases():
6060
) as conn:
6161
with conn.cursor() as cur:
6262
for db_name in databases_to_create:
63-
print(f"Ensuring database '{db_name}' exists.")
64-
cur.execute(f"CREATE DATABASE IF NOT EXISTS `{db_name}`;")
63+
print(f"Dropping and recreating database '{db_name}' to ensure it is empty.")
64+
cur.execute(f"DROP DATABASE IF EXISTS `{db_name}`;")
65+
cur.execute(f"CREATE DATABASE `{db_name}`;")
6566
print("--- Test databases are ready ---")
6667
except Exception as e:
67-
print(f"FATAL: Failed to create databases: {e}")
68+
print(f"FATAL: Failed to reset databases: {e}")
6869
sys.exit(1)
6970

7071

@@ -83,7 +84,7 @@ def setup_module(module):
8384
try:
8485
with open(sql_file, 'r') as f:
8586
sql_script = f.read()
86-
87+
8788
sql_statements = [s.strip() for s in sql_script.split(';') if s.strip()]
8889

8990
for db_name in databases:

0 commit comments

Comments
 (0)