From 54803801d7dc93b5c04482c6d88cc4a5aac5796c Mon Sep 17 00:00:00 2001 From: karezche <64801825+karenc-bq@users.noreply.github.com> Date: Wed, 6 May 2026 22:40:05 -0700 Subject: [PATCH] test: add clean up between tests --- .../sqlalchemy/test_sqlalchemy_basic.py | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/tests/integration/container/sqlalchemy/test_sqlalchemy_basic.py b/tests/integration/container/sqlalchemy/test_sqlalchemy_basic.py index 82427f95..79aa4a12 100644 --- a/tests/integration/container/sqlalchemy/test_sqlalchemy_basic.py +++ b/tests/integration/container/sqlalchemy/test_sqlalchemy_basic.py @@ -1,4 +1,4 @@ -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"). # You may not use this file except in compliance with the License. @@ -29,7 +29,6 @@ subqueryload) from sqlalchemy.sql import func -from tests.integration.container.utils.rds_test_utility import RdsTestUtility from ..utils.conditions import (disable_on_features, enable_on_deployments, enable_on_engines) from ..utils.database_engine import DatabaseEngine @@ -114,41 +113,29 @@ class Book(Base): TestEnvironmentFeatures.BLUE_GREEN_DEPLOYMENT, TestEnvironmentFeatures.PERFORMANCE]) class TestSqlAlchemy: - @pytest.fixture(scope='class') - def rds_utils(self): - region: str = TestEnvironment.get_current().get_info().get_region() - return RdsTestUtility(region) - - - @pytest.fixture(scope="class") + @pytest.fixture(scope="function") def engine(self, conn_utils): conn_str = f'mysql+aws_wrapper_mysqlconnector://{conn_utils.user}:{conn_utils.password}@{conn_utils.writer_cluster_host}:{conn_utils.port}/{conn_utils.dbname}' engine = create_engine(conn_str) Base.metadata.create_all(engine) yield engine Base.metadata.drop_all(engine) + engine.dispose() - @pytest.fixture(scope="class") - def Session(self, engine): - Session = sessionmaker(bind=engine) - yield Session - - @pytest.fixture(scope="class") - def session(self, Session): - session = Session() + @pytest.fixture(scope="function") + def session(self, engine): + session = sessionmaker(bind=engine)() yield session session.rollback() session.close() - def test_sqlalchemy_backend_configuration(self, test_environment: TestEnvironment, engine): + def test_sqlalchemy_backend_configuration(self, test_environment: TestEnvironment, session): """Test SQLAlchemy backend configuration with empty plugins""" # Verify that the connection is using the AWS wrapper - with engine.connect() as connection: - assert connection.connection is not None + assert session.connection().connection is not None # Test basic connection functionality - with Session(engine) as session: - assert session.query(TestModel).count() == 0 + assert session.query(TestModel).count() == 0 def test_sqlalchemy_basic_model_operations(self, session, test_environment: TestEnvironment): """Test basic SQLAlchemy ORM operations (CRUD)"""