]> git.ipfire.org Git - thirdparty/sqlalchemy/alembic.git/commitdiff
adjust autocommit tests to accommodate for execution_options change
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 5 Nov 2021 20:58:27 +0000 (16:58 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 5 Nov 2021 20:58:27 +0000 (16:58 -0400)
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

alembic/testing/suite/test_environment.py

index a761632b33d278cfd426da09c4440a792f9529e1..6c1009ec0ce3a00bf6665fd999533e4ec827e568 100644 (file)
@@ -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):