From: Mike Bayer Date: Fri, 5 Nov 2021 20:58:27 +0000 (-0400) Subject: adjust autocommit tests to accommodate for execution_options change X-Git-Tag: rel_1_7_5~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af7963889abffe2ab8dc640d4fdcb8cea6d53942;p=thirdparty%2Fsqlalchemy%2Falembic.git adjust autocommit tests to accommodate for execution_options change the tests here were relying on the fact that execution_options returns a new connection which is not the case for future mode. Change-Id: Ib6c2c69243a615fa2097c68fc5c35c14507bea61 --- diff --git a/alembic/testing/suite/test_environment.py b/alembic/testing/suite/test_environment.py index a761632b..6c1009ec 100644 --- a/alembic/testing/suite/test_environment.py +++ b/alembic/testing/suite/test_environment.py @@ -4,8 +4,11 @@ from ...migration import MigrationContext from ...testing import assert_raises from ...testing import config from ...testing import eq_ +from ...testing import is_ from ...testing import is_false +from ...testing import is_not_ from ...testing import is_true +from ...testing import ne_ from ...testing.fixtures import TestBase @@ -230,8 +233,29 @@ class MigrationTransactionTest(TestBase): is_true(self.conn.in_transaction()) with context.autocommit_block(): - is_false(self.conn.in_transaction()) - + # in 1.x, self.conn is separate due to the + # execution_options call. however for future they are the + # same connection and there is a "transaction" block + # despite autocommit + if self.is_sqlalchemy_future: + is_(context.connection, self.conn) + else: + is_not_(context.connection, self.conn) + is_false(self.conn.in_transaction()) + + eq_( + context.connection._execution_options[ + "isolation_level" + ], + "AUTOCOMMIT", + ) + + ne_( + context.connection._execution_options.get( + "isolation_level", None + ), + "AUTOCOMMIT", + ) is_true(self.conn.in_transaction()) is_false(self.conn.in_transaction()) @@ -244,7 +268,27 @@ class MigrationTransactionTest(TestBase): is_false(self.conn.in_transaction()) with context.autocommit_block(): - is_false(self.conn.in_transaction()) + is_true(context.connection.in_transaction()) + + # in 1.x, self.conn is separate due to the execution_options + # call. however for future they are the same connection and there + # is a "transaction" block despite autocommit + if self.is_sqlalchemy_future: + is_(context.connection, self.conn) + else: + is_not_(context.connection, self.conn) + is_false(self.conn.in_transaction()) + + eq_( + context.connection._execution_options["isolation_level"], + "AUTOCOMMIT", + ) + + ne_( + context.connection._execution_options.get("isolation_level", None), + "AUTOCOMMIT", + ) + is_false(self.conn.in_transaction()) def test_autocommit_block_transactional_ddl_sqlmode(self):