diff --git a/tests/integration/dbapi/async/V2/conftest.py b/tests/integration/dbapi/async/V2/conftest.py index d4117d37d3..f96ef7826e 100644 --- a/tests/integration/dbapi/async/V2/conftest.py +++ b/tests/integration/dbapi/async/V2/conftest.py @@ -1,4 +1,4 @@ -from random import randint +from random import choice, randint from typing import Tuple from pytest import fixture @@ -79,6 +79,9 @@ async def engine_v2( engine_name: str, ) -> str: cursor = connection_system_engine_v2.cursor() + # randomize the db name to avoid conflicts + suffix = "".join(choice("0123456789") for _ in range(2)) + engine_name = f"{engine_name}{suffix}_async" await cursor.execute(f"CREATE ENGINE IF NOT EXISTS {engine_name}") await cursor.execute(f"START ENGINE {engine_name}") yield engine_name @@ -86,6 +89,17 @@ async def engine_v2( await cursor.execute(f"DROP ENGINE IF EXISTS {engine_name}") +@fixture +async def setup_v2_db(connection_system_engine_v2: Connection, use_db_name: str): + use_db_name = use_db_name + "_async" + with connection_system_engine_v2.cursor() as cursor: + # randomize the db name to avoid conflicts + suffix = "".join(choice("0123456789") for _ in range(2)) + await cursor.execute(f"CREATE DATABASE {use_db_name}{suffix}") + yield f"{use_db_name}{suffix}" + await cursor.execute(f"DROP DATABASE {use_db_name}{suffix}") + + @fixture async def connection_system_engine_no_db( auth: Auth, diff --git a/tests/integration/dbapi/async/V2/test_queries_async.py b/tests/integration/dbapi/async/V2/test_queries_async.py index 0768600ffc..e053e5c8a5 100644 --- a/tests/integration/dbapi/async/V2/test_queries_async.py +++ b/tests/integration/dbapi/async/V2/test_queries_async.py @@ -2,10 +2,10 @@ from datetime import date, datetime from decimal import Decimal from os import environ -from random import choice, randint +from random import randint from typing import Callable, Generator, List -from pytest import fixture, mark, raises +from pytest import mark, raises from firebolt.async_db import Binary, Connection, Cursor, OperationalError from firebolt.async_db.connection import connect @@ -434,17 +434,6 @@ async def test_bytea_roundtrip( ), "Invalid bytea data returned after roundtrip" -@fixture -async def setup_v2_db(connection_system_engine_v2: Connection, use_db_name: str): - use_db_name = use_db_name + "_async" - with connection_system_engine_v2.cursor() as cursor: - # randomize the db name to avoid conflicts - suffix = "".join(choice("0123456789") for _ in range(2)) - await cursor.execute(f"CREATE DATABASE {use_db_name}{suffix}") - yield f"{use_db_name}{suffix}" - await cursor.execute(f"DROP DATABASE {use_db_name}{suffix}") - - @mark.xfail("dev" not in environ[API_ENDPOINT_ENV], reason="Only works on dev") async def test_use_database( setup_v2_db, diff --git a/tests/integration/dbapi/async/V2/test_system_engine_async.py b/tests/integration/dbapi/async/V2/test_system_engine_async.py index 76eb8212c6..0af65a6ec5 100644 --- a/tests/integration/dbapi/async/V2/test_system_engine_async.py +++ b/tests/integration/dbapi/async/V2/test_system_engine_async.py @@ -83,18 +83,17 @@ async def test_system_engine_v2_account(connection_system_engine_v2: Connection) async def test_system_engine_use_engine( - connection_system_engine_v2: Connection, database_name: str, engine_name: str + connection_system_engine_v2: Connection, setup_v2_db: str, engine_v2: str ): + table_name = "test_table_async" with connection_system_engine_v2.cursor() as cursor: - await cursor.execute(f"CREATE DATABASE IF NOT EXISTS {database_name}") - await cursor.execute(f"USE DATABASE {database_name}") - await cursor.execute(f"CREATE ENGINE IF NOT EXISTS {engine_name}") - await cursor.execute(f"USE ENGINE {engine_name}") - await cursor.execute("CREATE TABLE IF NOT EXISTS test_table (id int)") + await cursor.execute(f"USE DATABASE {setup_v2_db}") + await cursor.execute(f"USE ENGINE {engine_v2}") + await cursor.execute(f"CREATE TABLE IF NOT EXISTS {table_name} (id int)") # This query fails if we're not on a user engine - await cursor.execute("INSERT INTO test_table VALUES (1)") + await cursor.execute(f"INSERT INTO {table_name} VALUES (1)") await cursor.execute("USE ENGINE system") # Werify we've switched to system by making previous query fail with raises(OperationalError): - await cursor.execute("INSERT INTO test_table VALUES (1)") - await cursor.execute("DROP TABLE IF EXISTS test_table") + await cursor.execute(f"INSERT INTO {table_name} VALUES (1)") + await cursor.execute(f"DROP TABLE IF EXISTS {table_name}") diff --git a/tests/integration/dbapi/sync/V2/conftest.py b/tests/integration/dbapi/sync/V2/conftest.py index 159ba7271b..6613631400 100644 --- a/tests/integration/dbapi/sync/V2/conftest.py +++ b/tests/integration/dbapi/sync/V2/conftest.py @@ -1,4 +1,4 @@ -from random import randint +from random import choice, randint from typing import Tuple from pytest import fixture @@ -78,6 +78,9 @@ def engine_v2( connection_system_engine_v2: Connection, engine_name: str, ) -> str: + # randomize the db name to avoid conflicts + suffix = "".join(choice("0123456789") for _ in range(2)) + engine_name = f"{engine_name}{suffix}_sync" cursor = connection_system_engine_v2.cursor() cursor.execute(f"CREATE ENGINE IF NOT EXISTS {engine_name}") cursor.execute(f"START ENGINE {engine_name}") @@ -86,6 +89,17 @@ def engine_v2( cursor.execute(f"DROP ENGINE IF EXISTS {engine_name}") +@fixture(scope="session") +def setup_v2_db(connection_system_engine_v2, use_db_name): + use_db_name = f"{use_db_name}_sync" + with connection_system_engine_v2.cursor() as cursor: + # randomize the db name to avoid conflicts + suffix = "".join(choice("0123456789") for _ in range(2)) + cursor.execute(f"CREATE DATABASE {use_db_name}{suffix}") + yield f"{use_db_name}{suffix}" + cursor.execute(f"DROP DATABASE {use_db_name}{suffix}") + + @fixture def connection_system_engine_no_db( auth: Auth, diff --git a/tests/integration/dbapi/sync/V2/test_queries.py b/tests/integration/dbapi/sync/V2/test_queries.py index 37de4bfa13..cf7e47a1c3 100644 --- a/tests/integration/dbapi/sync/V2/test_queries.py +++ b/tests/integration/dbapi/sync/V2/test_queries.py @@ -2,11 +2,11 @@ from datetime import date, datetime from decimal import Decimal from os import environ -from random import choice, randint +from random import randint from threading import Thread from typing import Any, Callable, Generator, List -from pytest import fixture, mark, raises +from pytest import mark, raises from firebolt.async_db.cursor import QueryStatus from firebolt.client.auth import Auth @@ -514,17 +514,6 @@ def test_bytea_roundtrip( ), "Invalid bytea data returned after roundtrip" -@fixture(scope="module") -def setup_v2_db(connection_system_engine_v2, use_db_name): - use_db_name = f"{use_db_name}_sync" - with connection_system_engine_v2.cursor() as cursor: - # randomize the db name to avoid conflicts - suffix = "".join(choice("0123456789") for _ in range(2)) - cursor.execute(f"CREATE DATABASE {use_db_name}{suffix}") - yield f"{use_db_name}{suffix}" - cursor.execute(f"DROP DATABASE {use_db_name}{suffix}") - - @mark.xfail("dev" not in environ[API_ENDPOINT_ENV], reason="Only works on dev") def test_use_database( setup_v2_db, diff --git a/tests/integration/dbapi/sync/V2/test_system_engine.py b/tests/integration/dbapi/sync/V2/test_system_engine.py index 8dc3c8df28..224c1b6eb4 100644 --- a/tests/integration/dbapi/sync/V2/test_system_engine.py +++ b/tests/integration/dbapi/sync/V2/test_system_engine.py @@ -83,18 +83,17 @@ def test_system_engine_v2_account(connection_system_engine_v2: Connection): def test_system_engine_use_engine( - connection_system_engine_v2: Connection, database_name: str, engine_name: str + connection_system_engine_v2: Connection, setup_v2_db: str, engine_v2: str ): + table_name = "test_table_sync" with connection_system_engine_v2.cursor() as cursor: - cursor.execute(f"CREATE DATABASE IF NOT EXISTS {database_name}") - cursor.execute(f"USE DATABASE {database_name}") - cursor.execute(f"CREATE ENGINE IF NOT EXISTS {engine_name}") - cursor.execute(f"USE ENGINE {engine_name}") - cursor.execute("CREATE TABLE IF NOT EXISTS test_table (id int)") + cursor.execute(f"USE DATABASE {setup_v2_db}") + cursor.execute(f"USE ENGINE {engine_v2}") + cursor.execute(f"CREATE TABLE IF NOT EXISTS {table_name} (id int)") # This query fails if we're not on a user engine - cursor.execute("INSERT INTO test_table VALUES (1)") + cursor.execute(f"INSERT INTO {table_name} VALUES (1)") cursor.execute("USE ENGINE system") # Werify we've switched to system by making previous query fail with raises(OperationalError): - cursor.execute("INSERT INTO test_table VALUES (1)") - cursor.execute("DROP TABLE IF EXISTS test_table") + cursor.execute(f"INSERT INTO {table_name} VALUES (1)") + cursor.execute(f"DROP TABLE IF EXISTS {table_name}")