]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Pass connection to TablesTest.insert_data()
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 14 Apr 2020 19:30:28 +0000 (15:30 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 15 Apr 2020 15:12:59 +0000 (11:12 -0400)
towards the goal of reducing verbosity and repetition
in test fixtures as well as that we are moving to
connection only for execution, move the insert_data()
classmethod to accept a connection and adjust all
fixtures to use it.

Change-Id: I3bf534acca0d5f4cda1d4da8ae91f1155b829b09

48 files changed:
lib/sqlalchemy/testing/fixtures.py
lib/sqlalchemy/testing/suite/test_cte.py
lib/sqlalchemy/testing/suite/test_deprecations.py
lib/sqlalchemy/testing/suite/test_results.py
lib/sqlalchemy/testing/suite/test_rowcount.py
lib/sqlalchemy/testing/suite/test_select.py
lib/sqlalchemy/testing/suite/test_update_delete.py
test/aaa_profiling/test_orm.py
test/dialect/mysql/test_for_update.py
test/dialect/mysql/test_query.py
test/dialect/oracle/test_types.py
test/dialect/postgresql/test_query.py
test/dialect/postgresql/test_types.py
test/ext/declarative/test_basic.py
test/ext/test_associationproxy.py
test/ext/test_horizontal_shard.py
test/ext/test_hybrid.py
test/ext/test_serializer.py
test/orm/inheritance/_poly_fixtures.py
test/orm/inheritance/test_assorted_poly.py
test/orm/inheritance/test_basic.py
test/orm/inheritance/test_concrete.py
test/orm/inheritance/test_poly_loading.py
test/orm/inheritance/test_poly_persistence.py
test/orm/inheritance/test_polymorphic_rel.py
test/orm/inheritance/test_relationship.py
test/orm/inheritance/test_single.py
test/orm/test_ac_relationships.py
test/orm/test_assorted_eager.py
test/orm/test_bundle.py
test/orm/test_cascade.py
test/orm/test_deferred.py
test/orm/test_eager_relations.py
test/orm/test_events.py
test/orm/test_expire.py
test/orm/test_froms.py
test/orm/test_joins.py
test/orm/test_lazy_relations.py
test/orm/test_mapper.py
test/orm/test_merge.py
test/orm/test_of_type.py
test/orm/test_relationships.py
test/orm/test_selectin_relations.py
test/orm/test_subquery_relations.py
test/orm/test_update_delete.py
test/sql/test_defaults.py
test/sql/test_deprecations.py
test/sql/test_resultset.py

index 4f608340195ff21b1318ef5013bc3f363260e219..e5e6c42fc0f0e7b66b9c86f6160868f73b04bf8a 100644 (file)
@@ -135,7 +135,8 @@ class TablesTest(TestBase):
     def _setup_once_inserts(cls):
         if cls.run_inserts == "once":
             cls._load_fixtures()
-            cls.insert_data()
+            with cls.bind.begin() as conn:
+                cls.insert_data(conn)
 
     @classmethod
     def _setup_once_tables(cls):
@@ -157,7 +158,8 @@ class TablesTest(TestBase):
     def _setup_each_inserts(self):
         if self.run_inserts == "each":
             self._load_fixtures()
-            self.insert_data()
+            with self.bind.begin() as conn:
+                self.insert_data(conn)
 
     def _teardown_each_tables(self):
         if self.run_define_tables == "each":
@@ -224,7 +226,7 @@ class TablesTest(TestBase):
         return {}
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         pass
 
     def sql_count_(self, count, fn):
index fab457606732a1171820ab7948d7fc654893c696..1ee6cac106d52fd532ee2d4e33fcb675b4af91be 100644 (file)
@@ -36,18 +36,17 @@ class CTETest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        with config.db.connect() as conn:
-            conn.execute(
-                cls.tables.some_table.insert(),
-                [
-                    {"id": 1, "data": "d1", "parent_id": None},
-                    {"id": 2, "data": "d2", "parent_id": 1},
-                    {"id": 3, "data": "d3", "parent_id": 1},
-                    {"id": 4, "data": "d4", "parent_id": 3},
-                    {"id": 5, "data": "d5", "parent_id": 3},
-                ],
-            )
+    def insert_data(cls, connection):
+        connection.execute(
+            cls.tables.some_table.insert(),
+            [
+                {"id": 1, "data": "d1", "parent_id": None},
+                {"id": 2, "data": "d2", "parent_id": 1},
+                {"id": 3, "data": "d3", "parent_id": 1},
+                {"id": 4, "data": "d4", "parent_id": 3},
+                {"id": 5, "data": "d5", "parent_id": 3},
+            ],
+        )
 
     def test_select_nonrecursive_round_trip(self):
         some_table = self.tables.some_table
index 126d82fe975888db7c88d17163797c43d7a0840d..8c25616a86b8603c8e65f6bcfcaf1ed8ada7d92e 100644 (file)
@@ -1,4 +1,3 @@
-from .. import config
 from .. import fixtures
 from ..assertions import eq_
 from ..schema import Column
@@ -23,17 +22,16 @@ class DeprecatedCompoundSelectTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        with config.db.connect() as conn:
-            conn.execute(
-                cls.tables.some_table.insert(),
-                [
-                    {"id": 1, "x": 1, "y": 2},
-                    {"id": 2, "x": 2, "y": 3},
-                    {"id": 3, "x": 3, "y": 4},
-                    {"id": 4, "x": 4, "y": 5},
-                ],
-            )
+    def insert_data(cls, connection):
+        connection.execute(
+            cls.tables.some_table.insert(),
+            [
+                {"id": 1, "x": 1, "y": 2},
+                {"id": 2, "x": 2, "y": 3},
+                {"id": 3, "x": 3, "y": 4},
+                {"id": 4, "x": 4, "y": 5},
+            ],
+        )
 
     def _assert_result(self, conn, select, result, params=()):
         eq_(conn.execute(select, params).fetchall(), result)
index 0cff7b61d39dd46ac9931f3580fe9b04ce338a5b..2eb986c74aaca7124d8aa1dfda199eb831dc3507 100644 (file)
@@ -1,6 +1,5 @@
 import datetime
 
-from .. import config
 from .. import engines
 from .. import fixtures
 from ..assertions import eq_
@@ -37,21 +36,20 @@ class RowFetchTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        with config.db.connect() as conn:
-            conn.execute(
-                cls.tables.plain_pk.insert(),
-                [
-                    {"id": 1, "data": "d1"},
-                    {"id": 2, "data": "d2"},
-                    {"id": 3, "data": "d3"},
-                ],
-            )
+    def insert_data(cls, connection):
+        connection.execute(
+            cls.tables.plain_pk.insert(),
+            [
+                {"id": 1, "data": "d1"},
+                {"id": 2, "data": "d2"},
+                {"id": 3, "data": "d3"},
+            ],
+        )
 
-            conn.execute(
-                cls.tables.has_dates.insert(),
-                [{"id": 1, "today": datetime.datetime(2006, 5, 12, 12, 0, 0)}],
-            )
+        connection.execute(
+            cls.tables.has_dates.insert(),
+            [{"id": 1, "today": datetime.datetime(2006, 5, 12, 12, 0, 0)}],
+        )
 
     def test_via_attr(self, connection):
         row = connection.execute(
index ae189bc79cbb31e8a4502ed60562b805052e5cca..06945ff2a7cc7bca144b60a59a9ae3a6302a6778 100644 (file)
@@ -6,7 +6,6 @@ from sqlalchemy import String
 from sqlalchemy import Table
 from sqlalchemy import testing
 from sqlalchemy import text
-from sqlalchemy.testing import config
 from sqlalchemy.testing import eq_
 from sqlalchemy.testing import fixtures
 
@@ -33,7 +32,7 @@ class RowCountTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         cls.data = data = [
             ("Angela", "A"),
             ("Andrew", "A"),
@@ -47,11 +46,10 @@ class RowCountTest(fixtures.TablesTest):
         ]
 
         employees_table = cls.tables.employees
-        with config.db.begin() as conn:
-            conn.execute(
-                employees_table.insert(),
-                [{"name": n, "department": d} for n, d in data],
-            )
+        connection.execute(
+            employees_table.insert(),
+            [{"name": n, "department": d} for n, d in data],
+        )
 
     def test_basic(self):
         employees_table = self.tables.employees
index 23f78961fcb0e8b28e17c600a17e1695e8502f45..c1f77a7c18cfc05842a8dc688269b2eddd6494e8 100644 (file)
@@ -41,15 +41,14 @@ class CollateTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        with config.db.connect() as conn:
-            conn.execute(
-                cls.tables.some_table.insert(),
-                [
-                    {"id": 1, "data": "collate data1"},
-                    {"id": 2, "data": "collate data2"},
-                ],
-            )
+    def insert_data(cls, connection):
+        connection.execute(
+            cls.tables.some_table.insert(),
+            [
+                {"id": 1, "data": "collate data1"},
+                {"id": 2, "data": "collate data2"},
+            ],
+        )
 
     def _assert_result(self, select, result):
         with config.db.connect() as conn:
@@ -91,16 +90,15 @@ class OrderByLabelTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        with config.db.connect() as conn:
-            conn.execute(
-                cls.tables.some_table.insert(),
-                [
-                    {"id": 1, "x": 1, "y": 2, "q": "q1", "p": "p3"},
-                    {"id": 2, "x": 2, "y": 3, "q": "q2", "p": "p2"},
-                    {"id": 3, "x": 3, "y": 4, "q": "q3", "p": "p1"},
-                ],
-            )
+    def insert_data(cls, connection):
+        connection.execute(
+            cls.tables.some_table.insert(),
+            [
+                {"id": 1, "x": 1, "y": 2, "q": "q1", "p": "p3"},
+                {"id": 2, "x": 2, "y": 3, "q": "q2", "p": "p2"},
+                {"id": 3, "x": 3, "y": 4, "q": "q3", "p": "p1"},
+            ],
+        )
 
     def _assert_result(self, select, result):
         with config.db.connect() as conn:
@@ -165,17 +163,16 @@ class LimitOffsetTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        with config.db.connect() as conn:
-            conn.execute(
-                cls.tables.some_table.insert(),
-                [
-                    {"id": 1, "x": 1, "y": 2},
-                    {"id": 2, "x": 2, "y": 3},
-                    {"id": 3, "x": 3, "y": 4},
-                    {"id": 4, "x": 4, "y": 5},
-                ],
-            )
+    def insert_data(cls, connection):
+        connection.execute(
+            cls.tables.some_table.insert(),
+            [
+                {"id": 1, "x": 1, "y": 2},
+                {"id": 2, "x": 2, "y": 3},
+                {"id": 3, "x": 3, "y": 4},
+                {"id": 4, "x": 4, "y": 5},
+            ],
+        )
 
     def _assert_result(self, select, result, params=()):
         with config.db.connect() as conn:
@@ -323,22 +320,21 @@ class JoinTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        with config.db.connect() as conn:
-            conn.execute(
-                cls.tables.a.insert(),
-                [{"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}],
-            )
+    def insert_data(cls, connection):
+        connection.execute(
+            cls.tables.a.insert(),
+            [{"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}],
+        )
 
-            conn.execute(
-                cls.tables.b.insert(),
-                [
-                    {"id": 1, "a_id": 1},
-                    {"id": 2, "a_id": 1},
-                    {"id": 4, "a_id": 2},
-                    {"id": 5, "a_id": 3},
-                ],
-            )
+        connection.execute(
+            cls.tables.b.insert(),
+            [
+                {"id": 1, "a_id": 1},
+                {"id": 2, "a_id": 1},
+                {"id": 4, "a_id": 2},
+                {"id": 5, "a_id": 3},
+            ],
+        )
 
     def test_inner_join_fk(self):
         a, b = self.tables("a", "b")
@@ -420,17 +416,16 @@ class CompoundSelectTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        with config.db.connect() as conn:
-            conn.execute(
-                cls.tables.some_table.insert(),
-                [
-                    {"id": 1, "x": 1, "y": 2},
-                    {"id": 2, "x": 2, "y": 3},
-                    {"id": 3, "x": 3, "y": 4},
-                    {"id": 4, "x": 4, "y": 5},
-                ],
-            )
+    def insert_data(cls, connection):
+        connection.execute(
+            cls.tables.some_table.insert(),
+            [
+                {"id": 1, "x": 1, "y": 2},
+                {"id": 2, "x": 2, "y": 3},
+                {"id": 3, "x": 3, "y": 4},
+                {"id": 4, "x": 4, "y": 5},
+            ],
+        )
 
     def _assert_result(self, select, result, params=()):
         with config.db.connect() as conn:
@@ -565,17 +560,16 @@ class PostCompileParamsTest(
         )
 
     @classmethod
-    def insert_data(cls):
-        with config.db.connect() as conn:
-            conn.execute(
-                cls.tables.some_table.insert(),
-                [
-                    {"id": 1, "x": 1, "y": 2, "z": "z1"},
-                    {"id": 2, "x": 2, "y": 3, "z": "z2"},
-                    {"id": 3, "x": 3, "y": 4, "z": "z3"},
-                    {"id": 4, "x": 4, "y": 5, "z": "z4"},
-                ],
-            )
+    def insert_data(cls, connection):
+        connection.execute(
+            cls.tables.some_table.insert(),
+            [
+                {"id": 1, "x": 1, "y": 2, "z": "z1"},
+                {"id": 2, "x": 2, "y": 3, "z": "z2"},
+                {"id": 3, "x": 3, "y": 4, "z": "z3"},
+                {"id": 4, "x": 4, "y": 5, "z": "z4"},
+            ],
+        )
 
     def test_compile(self):
         table = self.tables.some_table
@@ -683,17 +677,16 @@ class ExpandingBoundInTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        with config.db.connect() as conn:
-            conn.execute(
-                cls.tables.some_table.insert(),
-                [
-                    {"id": 1, "x": 1, "y": 2, "z": "z1"},
-                    {"id": 2, "x": 2, "y": 3, "z": "z2"},
-                    {"id": 3, "x": 3, "y": 4, "z": "z3"},
-                    {"id": 4, "x": 4, "y": 5, "z": "z4"},
-                ],
-            )
+    def insert_data(cls, connection):
+        connection.execute(
+            cls.tables.some_table.insert(),
+            [
+                {"id": 1, "x": 1, "y": 2, "z": "z1"},
+                {"id": 2, "x": 2, "y": 3, "z": "z2"},
+                {"id": 3, "x": 3, "y": 4, "z": "z3"},
+                {"id": 4, "x": 4, "y": 5, "z": "z4"},
+            ],
+        )
 
     def _assert_result(self, select, result, params=()):
         with config.db.connect() as conn:
@@ -885,23 +878,22 @@ class LikeFunctionsTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        with config.db.connect() as conn:
-            conn.execute(
-                cls.tables.some_table.insert(),
-                [
-                    {"id": 1, "data": "abcdefg"},
-                    {"id": 2, "data": "ab/cdefg"},
-                    {"id": 3, "data": "ab%cdefg"},
-                    {"id": 4, "data": "ab_cdefg"},
-                    {"id": 5, "data": "abcde/fg"},
-                    {"id": 6, "data": "abcde%fg"},
-                    {"id": 7, "data": "ab#cdefg"},
-                    {"id": 8, "data": "ab9cdefg"},
-                    {"id": 9, "data": "abcde#fg"},
-                    {"id": 10, "data": "abcd9fg"},
-                ],
-            )
+    def insert_data(cls, connection):
+        connection.execute(
+            cls.tables.some_table.insert(),
+            [
+                {"id": 1, "data": "abcdefg"},
+                {"id": 2, "data": "ab/cdefg"},
+                {"id": 3, "data": "ab%cdefg"},
+                {"id": 4, "data": "ab_cdefg"},
+                {"id": 5, "data": "abcde/fg"},
+                {"id": 6, "data": "abcde%fg"},
+                {"id": 7, "data": "ab#cdefg"},
+                {"id": 8, "data": "ab9cdefg"},
+                {"id": 9, "data": "abcde#fg"},
+                {"id": 10, "data": "abcd9fg"},
+            ],
+        )
 
     def _test(self, expr, expected):
         some_table = self.tables.some_table
@@ -997,12 +989,11 @@ class ComputedColumnTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        with config.db.begin() as conn:
-            conn.execute(
-                cls.tables.square.insert(),
-                [{"id": 1, "side": 10}, {"id": 10, "side": 42}],
-            )
+    def insert_data(cls, connection):
+        connection.execute(
+            cls.tables.square.insert(),
+            [{"id": 1, "side": 10}, {"id": 10, "side": 42}],
+        )
 
     def test_select_all(self):
         with config.db.connect() as conn:
index 6003a09941eaf7717be54dff2abfbfea31ef02ad..f7e6da98e15018aafa901d7d6bac75dbabf55e3c 100644 (file)
@@ -1,4 +1,3 @@
-from .. import config
 from .. import fixtures
 from ..assertions import eq_
 from ..schema import Column
@@ -21,16 +20,15 @@ class SimpleUpdateDeleteTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        with config.db.connect() as conn:
-            conn.execute(
-                cls.tables.plain_pk.insert(),
-                [
-                    {"id": 1, "data": "d1"},
-                    {"id": 2, "data": "d2"},
-                    {"id": 3, "data": "d3"},
-                ],
-            )
+    def insert_data(cls, connection):
+        connection.execute(
+            cls.tables.plain_pk.insert(),
+            [
+                {"id": 1, "data": "d1"},
+                {"id": 2, "data": "d2"},
+                {"id": 3, "data": "d3"},
+            ],
+        )
 
     def test_update(self, connection):
         t = self.tables.plain_pk
index cecb0f240a78d84ce6c4e62f051b5a3c345f4072..6560681bad09ec078c4b88ad4aaa3c95bd4db7bd 100644 (file)
@@ -74,11 +74,13 @@ class MergeTest(fixtures.MappedTest):
         mapper(Child, child)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         parent, child = cls.tables.parent, cls.tables.child
 
-        parent.insert().execute({"id": 1, "data": "p1"})
-        child.insert().execute({"id": 1, "data": "p1c1", "parent_id": 1})
+        connection.execute(parent.insert(), {"id": 1, "data": "p1"})
+        connection.execute(
+            child.insert(), {"id": 1, "data": "p1c1", "parent_id": 1}
+        )
 
     def test_merge_no_load(self):
         Parent = self.classes.Parent
@@ -189,13 +191,15 @@ class LoadManyToOneFromIdentityTest(fixtures.MappedTest):
         mapper(Child, child)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         parent, child = cls.tables.parent, cls.tables.child
 
-        child.insert().execute(
-            [{"id": i, "data": "c%d" % i} for i in range(1, 251)]
+        connection.execute(
+            child.insert(),
+            [{"id": i, "data": "c%d" % i} for i in range(1, 251)],
         )
-        parent.insert().execute(
+        connection.execute(
+            parent.insert(),
             [
                 {
                     "id": i,
@@ -203,7 +207,7 @@ class LoadManyToOneFromIdentityTest(fixtures.MappedTest):
                     "child_id": (i % 250) + 1,
                 }
                 for i in range(1, 1000)
-            ]
+            ],
         )
 
     def test_many_to_one_load_no_identity(self):
@@ -292,9 +296,9 @@ class MergeBackrefsTest(fixtures.MappedTest):
         mapper(D, d)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, B, C, D = cls.classes.A, cls.classes.B, cls.classes.C, cls.classes.D
-        s = Session()
+        s = Session(connection)
         s.add_all(
             [
                 A(
@@ -358,9 +362,9 @@ class DeferOptionsTest(fixtures.MappedTest):
         mapper(A, a)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A = cls.classes.A
-        s = Session()
+        s = Session(connection)
         s.add_all(
             [
                 A(
@@ -664,9 +668,9 @@ class SelectInEagerLoadTest(fixtures.MappedTest):
         mapper(C, c)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, B, C = cls.classes("A", "B", "C")
-        s = Session()
+        s = Session(connection)
         s.add(A(bs=[B(cs=[C()]), B(cs=[C()])]))
         s.commit()
 
@@ -795,9 +799,9 @@ class JoinedEagerLoadTest(fixtures.MappedTest):
         mapper(G, g)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, B, C, D, E, F, G = cls.classes("A", "B", "C", "D", "E", "F", "G")
-        s = Session()
+        s = Session(connection)
         s.add(
             A(
                 bs=[B(cs=[C(ds=[D()])]), B(cs=[C()])],
@@ -1161,9 +1165,9 @@ class AnnotatedOverheadTest(fixtures.MappedTest):
         mapper(A, a)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A = cls.classes.A
-        s = Session()
+        s = Session(connection)
         s.add_all([A(data="asdf") for i in range(5)])
         s.commit()
 
index 1e8df858f4d38ef9fe42e9b601d1a422f7b925cf..5897a094dfe78db48fabc66a9325d5d920257d29 100644 (file)
@@ -43,12 +43,12 @@ class MySQLForUpdateLockingTest(fixtures.DeclarativeMappedTest):
             __table_args__ = {"mysql_engine": "InnoDB"}
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A = cls.classes.A
         B = cls.classes.B
 
         # all the x/y are < 10
-        s = Session()
+        s = Session(connection)
         s.add_all(
             [
                 A(x=5, y=5, bs=[B(x=4, y=4), B(x=2, y=8), B(x=7, y=1)]),
index 0c1e623fe817a0ecaad24f19a3d821e82374f021..a7ed45b3bfe29bcd770d862ddc23b770059c2521 100644 (file)
@@ -231,19 +231,18 @@ class AnyAllTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         stuff = cls.tables.stuff
-        with testing.db.begin() as conn:
-            conn.execute(
-                stuff.insert(),
-                [
-                    {"id": 1, "value": 1},
-                    {"id": 2, "value": 2},
-                    {"id": 3, "value": 3},
-                    {"id": 4, "value": 4},
-                    {"id": 5, "value": 5},
-                ],
-            )
+        connection.execute(
+            stuff.insert(),
+            [
+                {"id": 1, "value": 1},
+                {"id": 2, "value": 2},
+                {"id": 3, "value": 3},
+                {"id": 4, "value": 4},
+                {"id": 5, "value": 5},
+            ],
+        )
 
     def test_any_w_comparator(self, connection):
         stuff = self.tables.stuff
index e0d97230c09ca6ab54c0bd752b486210a71700ff..ffcac65916f57d6cefd1934ac817beacd77393ab 100644 (file)
@@ -919,7 +919,7 @@ class LOBFetchTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         cls.data = data = [
             dict(
                 id=i,
@@ -929,8 +929,7 @@ class LOBFetchTest(fixtures.TablesTest):
             for i in range(1, 20)
         ]
 
-        with testing.db.begin() as conn:
-            conn.execute(cls.tables.z_test.insert(), data)
+        connection.execute(cls.tables.z_test.insert(), data)
 
         binary_table = cls.tables.binary_table
         fname = os.path.join(
@@ -939,9 +938,8 @@ class LOBFetchTest(fixtures.TablesTest):
         with open(fname, "rb") as file_:
             cls.stream = stream = file_.read(12000)
 
-        with testing.db.begin() as conn:
-            for i in range(1, 11):
-                conn.execute(binary_table.insert(), id=i, data=stream)
+        for i in range(1, 11):
+            connection.execute(binary_table.insert(), id=i, data=stream)
 
     def test_lobs_without_convert(self):
         engine = testing_engine(options=dict(auto_convert_lobs=False))
index 74ad19d1a5e68377267eda5e304dec72fa3c7dc7..7f311778e7d201fa3f6172ee88923f6bcacdd482 100644 (file)
@@ -948,14 +948,14 @@ class ExtractTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         # TODO: why does setting hours to anything
         # not affect the TZ in the DB col ?
         class TZ(datetime.tzinfo):
             def utcoffset(self, dt):
                 return datetime.timedelta(hours=4)
 
-        cls.bind.execute(
+        connection.execute(
             cls.tables.t.insert(),
             {
                 "dtme": datetime.datetime(2012, 5, 10, 12, 15, 25),
index 1903e47d48e99205cc70ee957e57934d564dce4c..34ea4d7ed91cfa5150ab4d5717302b16a3f7b462 100644 (file)
@@ -79,26 +79,25 @@ class FloatCoercionTest(fixtures.TablesTest, AssertsExecutionResults):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         data_table = cls.tables.data_table
 
-        with testing.db.begin() as connection:
-            connection.execute(
-                data_table.insert().values(
-                    [
-                        {"data": 3},
-                        {"data": 5},
-                        {"data": 7},
-                        {"data": 2},
-                        {"data": 15},
-                        {"data": 12},
-                        {"data": 6},
-                        {"data": 478},
-                        {"data": 52},
-                        {"data": 9},
-                    ]
-                )
+        connection.execute(
+            data_table.insert().values(
+                [
+                    {"data": 3},
+                    {"data": 5},
+                    {"data": 7},
+                    {"data": 2},
+                    {"data": 15},
+                    {"data": 12},
+                    {"data": 6},
+                    {"data": 478},
+                    {"data": 52},
+                    {"data": 9},
+                ]
             )
+        )
 
     def test_float_coercion(self, connection):
         data_table = self.tables.data_table
index cb70b59f1260badfead541d22b0b9a5fad9ba687..7dfcc70bbb5cf1a1896cb87ea5163d7f17e189c0 100644 (file)
@@ -2185,7 +2185,7 @@ def _produce_test(inline, stringbased):
                     )
 
         @classmethod
-        def insert_data(cls):
+        def insert_data(cls, connection):
             params = [
                 dict(list(zip(("id", "name"), column_values)))
                 for column_values in [
@@ -2196,8 +2196,9 @@ def _produce_test(inline, stringbased):
                 ]
             ]
 
-            User.__table__.insert().execute(params)
-            Address.__table__.insert().execute(
+            connection.execute(User.__table__.insert(), params)
+            connection.execute(
+                Address.__table__.insert(),
                 [
                     dict(list(zip(("id", "user_id", "email"), column_values)))
                     for column_values in [
@@ -2207,7 +2208,7 @@ def _produce_test(inline, stringbased):
                         (4, 8, "ed@lala.com"),
                         (5, 9, "fred@fred.com"),
                     ]
-                ]
+                ],
             )
 
         def test_aliased_join(self):
index ddca2f78e48870fc3068919f8af39460b16ce7e7..6fdcf3e1165a357c3815ee404e8f897c3667d747 100644 (file)
@@ -24,7 +24,6 @@ from sqlalchemy.orm import create_session
 from sqlalchemy.orm import mapper
 from sqlalchemy.orm import relationship
 from sqlalchemy.orm import Session
-from sqlalchemy.orm import sessionmaker
 from sqlalchemy.orm.collections import attribute_mapped_collection
 from sqlalchemy.orm.collections import collection
 from sqlalchemy.testing import assert_raises
@@ -1621,7 +1620,7 @@ class ComparatorTest(fixtures.MappedTest, AssertsCompiledSQL):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         UserKeyword, User, Keyword, Singular = (
             cls.classes.UserKeyword,
             cls.classes.User,
@@ -1629,7 +1628,7 @@ class ComparatorTest(fixtures.MappedTest, AssertsCompiledSQL):
             cls.classes.Singular,
         )
 
-        session = sessionmaker()()
+        session = Session(connection)
         words = ("quick", "brown", "fox", "jumped", "over", "the", "lazy")
         for ii in range(16):
             user = User("user%d" % ii)
@@ -1656,7 +1655,9 @@ class ComparatorTest(fixtures.MappedTest, AssertsCompiledSQL):
         session.commit()
         cls.u = user
         cls.kw = user.keywords[0]
-        cls.session = session
+
+        # TODO: this is not the correct pattern, use session per test
+        cls.session = Session(testing.db)
 
     def _equivalent(self, q_proxy, q_direct):
         proxy_sql = q_proxy.statement.compile(dialect=default.DefaultDialect())
@@ -3447,10 +3448,10 @@ class ScopeBehaviorTest(fixtures.DeclarativeMappedTest):
             data = Column(String(50))
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, B = cls.classes("A", "B")
 
-        s = Session(testing.db)
+        s = Session(connection)
         s.add_all(
             [
                 A(id=1, bs=[B(data="b1"), B(data="b2")]),
index 70a126f4f31f836484d0e06ddbab676bc3bed5d8..7665711a98a4c4aaf8cb9b639ee2d9415876eccb 100644 (file)
@@ -555,9 +555,9 @@ class RefreshDeferExpireTest(fixtures.DeclarativeMappedTest):
             deferred_data = deferred(Column(String(30)))
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A = cls.classes.A
-        s = Session()
+        s = Session(connection)
         s.add(A(data="d1", deferred_data="d2"))
         s.commit()
 
index ab57ce6f47ea6e7eb51702ec55dd385360d8cb9b..353c52c5c0d89c4bbbd16f00f1cd4eb2a82eb58d 100644 (file)
@@ -579,8 +579,8 @@ class BulkUpdateTest(fixtures.DeclarativeMappedTest, AssertsCompiledSQL):
                 return self.fname
 
     @classmethod
-    def insert_data(cls):
-        s = Session()
+    def insert_data(cls, connection):
+        s = Session(connection)
         jill = cls.classes.Person(id=3, first_name="jill")
         s.add(jill)
         s.commit()
index ac5133fdafa51d8a326ae4db017f06b38bc6ec9f..4080a0044b0282cd20f66faf81431b95fcf7fe02 100644 (file)
@@ -81,7 +81,7 @@ class SerializeTest(AssertsCompiledSQL, fixtures.MappedTest):
         configure_mappers()
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         params = [
             dict(list(zip(("id", "name"), column_values)))
             for column_values in [
@@ -91,8 +91,9 @@ class SerializeTest(AssertsCompiledSQL, fixtures.MappedTest):
                 (10, "chuck"),
             ]
         ]
-        users.insert().execute(params)
-        addresses.insert().execute(
+        connection.execute(users.insert(), params)
+        connection.execute(
+            addresses.insert(),
             [
                 dict(list(zip(("id", "user_id", "email"), column_values)))
                 for column_values in [
@@ -102,7 +103,7 @@ class SerializeTest(AssertsCompiledSQL, fixtures.MappedTest):
                     (4, 8, "ed@lala.com"),
                     (5, 9, "fred@fred.com"),
                 ]
-            ]
+            ],
         )
 
     def test_tables(self):
index 2a3a5dcfffb78e7a49017732ef2a3f34ba60372a..c9cde7a81cd1d5f3fba5d9f13ce8ece61447ae71 100644 (file)
@@ -151,7 +151,7 @@ class _PolymorphicFixtureBase(fixtures.MappedTest, AssertsCompiledSQL):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
 
         cls.e1 = e1 = Engineer(
             name="dilbert",
@@ -209,7 +209,7 @@ class _PolymorphicFixtureBase(fixtures.MappedTest, AssertsCompiledSQL):
         cls.c2 = c2 = Company(name="Elbonia, Inc.")
         c2.employees = [e3]
 
-        sess = create_session()
+        sess = create_session(connection)
         sess.add(c1)
         sess.add(c2)
         sess.flush()
index 616ed79a6cd6b55b0739930872d769241f489e24..029573c5fcd7a211279093734a700a8d0215ceaa 100644 (file)
@@ -1262,11 +1262,11 @@ class GenerativeTest(fixtures.MappedTest, AssertsExecutionResults):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Status, Person, Engineer, Manager, Car = cls.classes(
             "Status", "Person", "Engineer", "Manager", "Car"
         )
-        session = create_session()
+        session = create_session(connection)
 
         active = Status(name="active")
         dead = Status(name="dead")
index 9b896b59ab71e04a63b6ab95f4f823a09735f144..cb4e70ecb2e3cb7e0f42f594cabe5ed3feb5718a 100644 (file)
@@ -160,10 +160,10 @@ class PolyExpressionEagerLoad(fixtures.DeclarativeMappedTest):
             __mapper_args__ = {"polymorphic_identity": "b"}
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A = cls.classes.A
 
-        session = Session(testing.db)
+        session = Session(connection)
         session.add_all(
             [
                 A(id=1, discriminator="a"),
@@ -1975,14 +1975,18 @@ class DistinctPKTest(fixtures.MappedTest):
             pass
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         person_insert = person_table.insert()
-        person_insert.execute(id=1, name="alice")
-        person_insert.execute(id=2, name="bob")
+        connection.execute(person_insert, dict(id=1, name="alice"))
+        connection.execute(person_insert, dict(id=2, name="bob"))
 
         employee_insert = employee_table.insert()
-        employee_insert.execute(id=2, salary=250, person_id=1)  # alice
-        employee_insert.execute(id=3, salary=200, person_id=2)  # bob
+        connection.execute(
+            employee_insert, dict(id=2, salary=250, person_id=1)
+        )  # alice
+        connection.execute(
+            employee_insert, dict(id=3, salary=200, person_id=2)
+        )  # bob
 
     def test_implicit(self):
         person_mapper = mapper(Person, person_table)
@@ -3347,7 +3351,7 @@ class DiscriminatorOrPkNoneTest(fixtures.DeclarativeMappedTest):
             __mapper_args__ = {"polymorphic_identity": "b"}
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Parent, A, B = cls.classes("Parent", "A", "B")
         s = Session()
 
@@ -3455,7 +3459,7 @@ class UnexpectedPolymorphicIdentityTest(fixtures.DeclarativeMappedTest):
             __mapper_args__ = {"polymorphic_identity": "subb"}
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         ASingleSubA, ASingleSubB, AJoinedSubA, AJoinedSubB = cls.classes(
             "ASingleSubA", "ASingleSubB", "AJoinedSubA", "AJoinedSubB"
         )
index cea7eeaac87092eecb94143a51f456a229d306c0..376337b25399361029c98cef9ebd0a9e5f6175eb 100644 (file)
@@ -1171,12 +1171,14 @@ class ColKeysTest(fixtures.MappedTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        refugees_table.insert().execute(
+    def insert_data(cls, connection):
+        connection.execute(
+            refugees_table.insert(),
             dict(refugee_fid=1, name="refugee1"),
             dict(refugee_fid=2, name="refugee2"),
         )
-        offices_table.insert().execute(
+        connection.execute(
+            offices_table.insert(),
             dict(office_fid=1, name="office1"),
             dict(office_fid=2, name="office2"),
         )
index c40794ef4f8506f694f52a630fc992bb0d750e40..416a52f622e9f946720066ce7795f9acb74d54a3 100644 (file)
@@ -69,9 +69,9 @@ class BaseAndSubFixture(object):
             a_sub_id = Column(ForeignKey("asub.id"))
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, B, ASub, C = cls.classes("A", "B", "ASub", "C")
-        s = Session()
+        s = Session(connection)
         s.add(A(id=1, adata="adata", bs=[B(), B()]))
         s.add(
             ASub(
@@ -564,11 +564,11 @@ class LoaderOptionsTest(
             )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Parent, ChildSubclass1, Other = cls.classes(
             "Parent", "ChildSubclass1", "Other"
         )
-        session = Session()
+        session = Session(connection)
 
         parent = Parent(id=1)
         subclass1 = ChildSubclass1(id=1, parent=parent)
index deb33838f23679a7df89868b5fa17c00885fdb87..25eeb3d1df1b193b4749ba7f1173e3c0c91ee614 100644 (file)
@@ -318,7 +318,7 @@ class RoundTripTest(PolymorphTest):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         redefine_colprop = cls.redefine_colprop
         include_base = cls.include_base
 
@@ -356,7 +356,7 @@ class RoundTripTest(PolymorphTest):
             ),
         ]
 
-        session = Session()
+        session = Session(connection)
         c = Company(name="company1")
         c.employees = employees
         session.add(c)
index 830d60b9574f1cca9aed0c2bf5bf9f3b7e86e650..8be25f2b9d3034a53c363f266a572bd265509eea 100644 (file)
@@ -47,8 +47,8 @@ class _PolymorphicTestBase(object):
         )
 
     @classmethod
-    def insert_data(cls):
-        super(_PolymorphicTestBase, cls).insert_data()
+    def insert_data(cls, connection):
+        super(_PolymorphicTestBase, cls).insert_data(connection)
 
         global all_employees, c1_employees, c2_employees
         global c1, c2, e1, e2, e3, b1, m1
index b7d49829e01e061922eb03474350b032bf9af8eb..a4dde3f0231bcb1fbd4d02f9489e2d45d9b46ed4 100644 (file)
@@ -574,7 +574,7 @@ class M2MFilterTest(fixtures.MappedTest):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Organization = cls.classes.Organization
         e1 = Engineer(name="e1")
         e2 = Engineer(name="e2")
@@ -582,7 +582,7 @@ class M2MFilterTest(fixtures.MappedTest):
         e4 = Engineer(name="e4")
         org1 = Organization(name="org1", engineers=[e1, e2])
         org2 = Organization(name="org2", engineers=[e3, e4])
-        sess = create_session()
+        sess = create_session(connection)
         sess.add(org1)
         sess.add(org2)
         sess.flush()
@@ -900,13 +900,13 @@ class EagerToSubclassTest(fixtures.MappedTest):
         mapper(Related, related)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         global p1, p2
 
         Parent = cls.classes.Parent
         Sub = cls.classes.Sub
         Related = cls.classes.Related
-        sess = Session()
+        sess = Session(connection)
         r1, r2 = Related(data="r1"), Related(data="r2")
         s1 = Sub(data="s1", related=r1)
         s2 = Sub(data="s2", related=r2)
@@ -1079,11 +1079,11 @@ class SubClassEagerToSubClassTest(fixtures.MappedTest):
         mapper(Sub, sub, inherits=Base, polymorphic_identity="s")
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         global p1, p2
 
         Sub, Subparent = cls.classes.Sub, cls.classes.Subparent
-        sess = create_session()
+        sess = create_session(connection)
         p1 = Subparent(
             data="p1",
             children=[Sub(data="s1"), Sub(data="s2"), Sub(data="s3")],
@@ -1265,12 +1265,12 @@ class SameNamedPropTwoPolymorphicSubClassesTest(fixtures.MappedTest):
         mapper(D, cls.tables.d)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         B = cls.classes.B
         C = cls.classes.C
         D = cls.classes.D
 
-        session = Session()
+        session = Session(connection)
 
         d = D()
         session.add_all([B(related=[d]), C(related=[d])])
@@ -1438,10 +1438,10 @@ class SubClassToSubClassFromParentTest(fixtures.MappedTest):
         mapper(D, cls.tables.d, inherits=A, polymorphic_identity="d")
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         B = cls.classes.B
 
-        session = Session()
+        session = Session(connection)
         session.add(B())
         session.commit()
 
@@ -1784,7 +1784,7 @@ class JoinedloadWPolyOfTypeContinued(
             id = Column(Integer, primary_key=True)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         User, Fred, SubBar, Bar, SubFoo = cls.classes(
             "User", "Fred", "SubBar", "Bar", "SubFoo"
         )
@@ -1794,7 +1794,7 @@ class JoinedloadWPolyOfTypeContinued(
         sub_bar = SubBar(fred=fred)
         rectangle = SubFoo(owner=user, baz=10, bar=bar, sub_bar=sub_bar)
 
-        s = Session()
+        s = Session(connection)
         s.add_all([user, fred, bar, sub_bar, rectangle])
         s.commit()
 
@@ -2730,9 +2730,9 @@ class M2ODontLoadSiblingTest(fixtures.DeclarativeMappedTest):
             child2 = relationship(Child2, viewonly=True)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Other, Child1 = cls.classes("Other", "Child1")
-        s = Session()
+        s = Session(connection)
         obj = Other(parent=Child1())
         s.add(obj)
         s.commit()
index 553380ac7bf33a1ae0b4208544cc77639864b6e4..b32a8af3d7d6189e6c2700c7adb86e56b4f69f3f 100644 (file)
@@ -1336,11 +1336,11 @@ class ManyToManyToSingleTest(fixtures.MappedTest, AssertsCompiledSQL):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Parent = cls.classes.Parent
         SubChild1 = cls.classes.SubChild1
         SubChild2 = cls.classes.SubChild2
-        s = Session()
+        s = Session(connection)
         s.add_all(
             [
                 Parent(
index bb99636d4206efebfe7673467a518113b2992502..ce2dbddf7becbd5e14f464f9a9a3fda7faa84747 100644 (file)
@@ -58,10 +58,10 @@ class PartitionByFixture(fixtures.DeclarativeMappedTest):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, B, C = cls.classes("A", "B", "C")
 
-        s = Session(testing.db)
+        s = Session(connection)
         s.add_all([A(id=i) for i in range(1, 4)])
         s.flush()
         s.add_all(
@@ -198,9 +198,9 @@ class AltSelectableTest(
         A.b = relationship(B_viacd, primaryjoin=A.b_id == j.c.b_id)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, B, C, D = cls.classes("A", "B", "C", "D")
-        sess = Session()
+        sess = Session(connection)
 
         for obj in [
             B(id=1),
index 5c62165f9aa343e2ffa28b912f818a93e15dfd73..df391771228f9b68c6a2b446109b7ef873612d5c 100644 (file)
@@ -143,7 +143,7 @@ class EagerTest(fixtures.MappedTest):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Owner, Category, Option, Thing = (
             cls.classes.Owner,
             cls.classes.Category,
@@ -151,7 +151,7 @@ class EagerTest(fixtures.MappedTest):
             cls.classes.Thing,
         )
 
-        session = create_session()
+        session = create_session(connection)
 
         o = Owner()
         c = Category(name="Some Category")
index a17a00ed0dcdb9b433b759bcb8fa49da37bb2d8b..f6d4e8e37fa745893393af245fcf2b9830fa2388 100644 (file)
@@ -64,8 +64,8 @@ class BundleTest(fixtures.MappedTest, AssertsCompiledSQL):
         mapper(cls.classes.Other, cls.tables.other)
 
     @classmethod
-    def insert_data(cls):
-        sess = Session()
+    def insert_data(cls, connection):
+        sess = Session(connection)
         sess.add_all(
             [
                 cls.classes.Data(
index 815df36203998049ced8c3b03cbaa582aaaaa3f2..7b54f3bc1c5e40f36ba992d5973b6012137ac080 100644 (file)
@@ -1576,7 +1576,7 @@ class M2OCascadeDeleteOrphanTestOne(fixtures.MappedTest):
         mapper(Foo, foo)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Pref, User, Extra = (
             cls.classes.Pref,
             cls.classes.User,
@@ -1586,7 +1586,7 @@ class M2OCascadeDeleteOrphanTestOne(fixtures.MappedTest):
         u1 = User(name="ed", pref=Pref(data="pref 1", extra=[Extra()]))
         u2 = User(name="jack", pref=Pref(data="pref 2", extra=[Extra()]))
         u3 = User(name="foo", pref=Pref(data="pref 3", extra=[Extra()]))
-        sess = create_session()
+        sess = create_session(connection)
         sess.add_all((u1, u2, u3))
         sess.flush()
         sess.close()
index a02ee250ca28bfebe0e5830267fb949108d73c99..b9198033b9052cd9d25fb01d8fe272d29bb7ee12 100644 (file)
@@ -1256,10 +1256,10 @@ class SelfReferentialMultiPathTest(testing.fixtures.DeclarativeMappedTest):
             name = sa.Column(sa.String(10))
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Node = cls.classes.Node
 
-        session = Session()
+        session = Session(connection)
         session.add_all(
             [
                 Node(id=1, name="name"),
@@ -1721,9 +1721,9 @@ class WithExpressionTest(fixtures.DeclarativeMappedTest):
             b_expr = query_expression()
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, B = cls.classes("A", "B")
-        s = Session()
+        s = Session(connection)
 
         s.add_all(
             [
@@ -1866,9 +1866,9 @@ class RaiseLoadTest(fixtures.DeclarativeMappedTest):
             z = deferred(Column(Integer), raiseload=True)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A = cls.classes.A
-        s = Session()
+        s = Session(connection)
         s.add(A(id=1, x=2, y=3, z=4))
         s.commit()
 
index ecc3711176c6ae38ac0dbf9da21934b765c51c64..3a6810d805a82dc884eaa0df58c7f98feb860257 100644 (file)
@@ -3000,8 +3000,8 @@ class InnerJoinSplicingTest(fixtures.MappedTest, testing.AssertsCompiledSQL):
         ]
 
     @classmethod
-    def insert_data(cls):
-        s = Session(testing.db)
+    def insert_data(cls, connection):
+        s = Session(connection)
         s.add_all(cls._fixture_data())
         s.commit()
 
@@ -3228,8 +3228,8 @@ class InnerJoinSplicingWSecondaryTest(
         ]
 
     @classmethod
-    def insert_data(cls):
-        s = Session(testing.db)
+    def insert_data(cls, connection):
+        s = Session(connection)
         s.add_all(cls._fixture_data())
         s.commit()
 
@@ -4236,25 +4236,34 @@ class MixedSelfReferentialEagerTest(fixtures.MappedTest):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         b_table, a_table = cls.tables.b_table, cls.tables.a_table
 
-        a_table.insert().execute(dict(id=1), dict(id=2), dict(id=3))
-        b_table.insert().execute(
-            dict(id=1, parent_a_id=2, parent_b1_id=None, parent_b2_id=None),
-            dict(id=2, parent_a_id=1, parent_b1_id=1, parent_b2_id=None),
-            dict(id=3, parent_a_id=1, parent_b1_id=1, parent_b2_id=2),
-            dict(id=4, parent_a_id=3, parent_b1_id=1, parent_b2_id=None),
-            dict(id=5, parent_a_id=3, parent_b1_id=None, parent_b2_id=2),
-            dict(id=6, parent_a_id=1, parent_b1_id=1, parent_b2_id=3),
-            dict(id=7, parent_a_id=2, parent_b1_id=None, parent_b2_id=3),
-            dict(id=8, parent_a_id=2, parent_b1_id=1, parent_b2_id=2),
-            dict(id=9, parent_a_id=None, parent_b1_id=1, parent_b2_id=None),
-            dict(id=10, parent_a_id=3, parent_b1_id=7, parent_b2_id=2),
-            dict(id=11, parent_a_id=3, parent_b1_id=1, parent_b2_id=8),
-            dict(id=12, parent_a_id=2, parent_b1_id=5, parent_b2_id=2),
-            dict(id=13, parent_a_id=3, parent_b1_id=4, parent_b2_id=4),
-            dict(id=14, parent_a_id=3, parent_b1_id=7, parent_b2_id=2),
+        connection.execute(
+            a_table.insert(), [dict(id=1), dict(id=2), dict(id=3)]
+        )
+        connection.execute(
+            b_table.insert(),
+            [
+                dict(
+                    id=1, parent_a_id=2, parent_b1_id=None, parent_b2_id=None
+                ),
+                dict(id=2, parent_a_id=1, parent_b1_id=1, parent_b2_id=None),
+                dict(id=3, parent_a_id=1, parent_b1_id=1, parent_b2_id=2),
+                dict(id=4, parent_a_id=3, parent_b1_id=1, parent_b2_id=None),
+                dict(id=5, parent_a_id=3, parent_b1_id=None, parent_b2_id=2),
+                dict(id=6, parent_a_id=1, parent_b1_id=1, parent_b2_id=3),
+                dict(id=7, parent_a_id=2, parent_b1_id=None, parent_b2_id=3),
+                dict(id=8, parent_a_id=2, parent_b1_id=1, parent_b2_id=2),
+                dict(
+                    id=9, parent_a_id=None, parent_b1_id=1, parent_b2_id=None
+                ),
+                dict(id=10, parent_a_id=3, parent_b1_id=7, parent_b2_id=2),
+                dict(id=11, parent_a_id=3, parent_b1_id=1, parent_b2_id=8),
+                dict(id=12, parent_a_id=2, parent_b1_id=5, parent_b2_id=2),
+                dict(id=13, parent_a_id=3, parent_b1_id=4, parent_b2_id=4),
+                dict(id=14, parent_a_id=3, parent_b1_id=7, parent_b2_id=2),
+            ],
         )
 
     def test_eager_load(self):
@@ -4854,16 +4863,18 @@ class CorrelatedSubqueryTest(fixtures.MappedTest):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         stuff, users = cls.tables.stuff, cls.tables.users
 
-        users.insert().execute(
+        connection.execute(
+            users.insert(),
             {"id": 1, "name": "user1"},
             {"id": 2, "name": "user2"},
             {"id": 3, "name": "user3"},
         )
 
-        stuff.insert().execute(
+        connection.execute(
+            stuff.insert(),
             {"id": 1, "user_id": 1, "date": datetime.date(2007, 10, 15)},
             {"id": 2, "user_id": 1, "date": datetime.date(2007, 12, 15)},
             {"id": 3, "user_id": 1, "date": datetime.date(2007, 11, 15)},
@@ -5567,9 +5578,9 @@ class LazyLoadOptSpecificityTest(fixtures.DeclarativeMappedTest):
             b_id = Column(ForeignKey("b.id"))
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, B, C = cls.classes("A", "B", "C")
-        s = Session()
+        s = Session(connection)
         s.add(A(id=1, bs=[B(cs=[C()])]))
         s.add(A(id=2))
         s.commit()
index c25970e2c247d8439eb0090d06f15ce8c2c197d2..225468baab91277a365ddabd83d5ea1e6c2d82a0 100644 (file)
@@ -653,9 +653,9 @@ class RestoreLoadContextTest(fixtures.DeclarativeMappedTest):
             a_id = Column(ForeignKey("a.id"))
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, B = cls.classes("A", "B")
-        s = Session(testing.db)
+        s = Session(connection)
         s.add(A(bs=[B(), B(), B()]))
         s.commit()
 
index 127380fad678e8528e30494bbebcbdc9221edc4b..f38f917da00bb969442f3aed14b5b54bb8d9b359 100644 (file)
@@ -1385,15 +1385,17 @@ class PolymorphicExpireTest(fixtures.MappedTest):
             pass
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         people, engineers = cls.tables.people, cls.tables.engineers
 
-        people.insert().execute(
+        connection.execute(
+            people.insert(),
             {"person_id": 1, "name": "person1", "type": "person"},
             {"person_id": 2, "name": "engineer1", "type": "engineer"},
             {"person_id": 3, "name": "engineer2", "type": "engineer"},
         )
-        engineers.insert().execute(
+        connection.execute(
+            engineers.insert(),
             {"person_id": 2, "status": "new engineer"},
             {"person_id": 3, "status": "old engineer"},
         )
index 5ac4a15ec5d358af20af341406a75eaf5ad44ebd..08b59ce67e26da98168de84ecd25b60bf27edada 100644 (file)
@@ -805,10 +805,10 @@ class AddEntityEquivalenceTest(fixtures.MappedTest, AssertsCompiledSQL):
         mapper(D, d, inherits=A, polymorphic_identity="d")
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, C, B = (cls.classes.A, cls.classes.C, cls.classes.B)
 
-        sess = create_session()
+        sess = create_session(connection)
         sess.add_all(
             [
                 B(name="b1"),
@@ -3533,8 +3533,8 @@ class LabelCollideTest(fixtures.MappedTest):
         mapper(cls.classes.Bar, cls.tables.foo_bar)
 
     @classmethod
-    def insert_data(cls):
-        s = Session()
+    def insert_data(cls, connection):
+        s = Session(connection)
         s.add_all([cls.classes.Foo(id=1, bar_id=2), cls.classes.Bar(id=3)])
         s.commit()
 
index 2cd30d88d751fe3a321ff501f6d4b8bb05c60903..1895a41e86f523f097b599a0b8453a46e6e21a24 100644 (file)
@@ -3091,10 +3091,10 @@ class SelfReferentialTest(fixtures.MappedTest, AssertsCompiledSQL):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Node = cls.classes.Node
 
-        sess = create_session()
+        sess = create_session(connection)
         n1 = Node(data="n1")
         n1.append(Node(data="n11"))
         n1.append(Node(data="n12"))
@@ -3801,7 +3801,7 @@ class SelfReferentialM2MTest(fixtures.MappedTest):
             pass
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Node, nodes, node_to_nodes = (
             cls.classes.Node,
             cls.tables.nodes,
@@ -3821,7 +3821,7 @@ class SelfReferentialM2MTest(fixtures.MappedTest):
                 )
             },
         )
-        sess = create_session()
+        sess = create_session(connection)
         n1 = Node(data="n1")
         n2 = Node(data="n2")
         n3 = Node(data="n3")
index 1c27208989a474fed4c1ede417b4868850b90769..be8301bae75c87533bef406d6919806c8bc36276 100644 (file)
@@ -1248,16 +1248,18 @@ class CorrelatedTest(fixtures.MappedTest):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         stuff, user_t = cls.tables.stuff, cls.tables.user_t
 
-        user_t.insert().execute(
+        connection.execute(
+            user_t.insert(),
             {"id": 1, "name": "user1"},
             {"id": 2, "name": "user2"},
             {"id": 3, "name": "user3"},
         )
 
-        stuff.insert().execute(
+        connection.execute(
+            stuff.insert(),
             {"id": 1, "user_id": 1, "date": datetime.date(2007, 10, 15)},
             {"id": 2, "user_id": 1, "date": datetime.date(2007, 12, 15)},
             {"id": 3, "user_id": 1, "date": datetime.date(2007, 11, 15)},
index e4ba50f13eaf26759bd17bea071ca6adf57a94c4..545bf8e016e8b3b4f21ffa75971e3908731a7314 100644 (file)
@@ -2845,7 +2845,7 @@ class SecondaryOptionsTest(fixtures.MappedTest):
         mapper(Related, related)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         child1, child2, base, related = (
             cls.tables.child1,
             cls.tables.child2,
@@ -2853,7 +2853,8 @@ class SecondaryOptionsTest(fixtures.MappedTest):
             cls.tables.related,
         )
 
-        base.insert().execute(
+        connection.execute(
+            base.insert(),
             [
                 {"id": 1, "type": "child1"},
                 {"id": 2, "type": "child1"},
@@ -2861,18 +2862,20 @@ class SecondaryOptionsTest(fixtures.MappedTest):
                 {"id": 4, "type": "child2"},
                 {"id": 5, "type": "child2"},
                 {"id": 6, "type": "child2"},
-            ]
+            ],
         )
-        child2.insert().execute([{"id": 4}, {"id": 5}, {"id": 6}])
-        child1.insert().execute(
+        connection.execute(child2.insert(), [{"id": 4}, {"id": 5}, {"id": 6}])
+        connection.execute(
+            child1.insert(),
             [
                 {"id": 1, "child2id": 4},
                 {"id": 2, "child2id": 5},
                 {"id": 3, "child2id": 6},
-            ]
+            ],
         )
-        related.insert().execute(
-            [{"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}, {"id": 6}]
+        connection.execute(
+            related.insert(),
+            [{"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}, {"id": 6}],
         )
 
     def test_contains_eager(self):
@@ -3033,13 +3036,13 @@ class DeferredPopulationTest(fixtures.MappedTest):
         mapper(Thing, thing, properties={"name": deferred(thing.c.name)})
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         thing, human = cls.tables.thing, cls.tables.human
 
-        thing.insert().execute([{"id": 1, "name": "Chair"}])
+        connection.execute(thing.insert(), [{"id": 1, "name": "Chair"}])
 
-        human.insert().execute(
-            [{"id": 1, "thing_id": 1, "name": "Clark Kent"}]
+        connection.execute(
+            human.insert(), [{"id": 1, "thing_id": 1, "name": "Clark Kent"}]
         )
 
     def _test(self, thing):
index b5e1ee415039bd940c0e95d37f1843123fb6eb04..6b03717d3d385d5a1f4cca571d211e1232dc6756 100644 (file)
@@ -1695,9 +1695,9 @@ class M2ONoUseGetLoadingTest(fixtures.MappedTest):
         assert Address.user.property._use_get is False
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         User, Address = cls.classes.User, cls.classes.Address
-        s = Session()
+        s = Session(connection)
         s.add_all(
             [
                 User(
index 9e9387db94900a165bfb1cac8d6ce6a8e4cb5e92..82930f754fd2dd5344925deb0aa4ea3521735cb7 100644 (file)
@@ -569,8 +569,8 @@ class SubclassRelationshipTest(
             name = Column(String(10))
 
     @classmethod
-    def insert_data(cls):
-        s = Session(testing.db)
+    def insert_data(cls, connection):
+        s = Session(connection)
 
         s.add_all(cls._fixture())
         s.commit()
@@ -1027,8 +1027,8 @@ class SubclassRelationshipTest2(
             c = relationship("C", backref="ds")
 
     @classmethod
-    def insert_data(cls):
-        s = Session(testing.db)
+    def insert_data(cls, connection):
+        s = Session(connection)
 
         s.add_all(cls._fixture())
         s.commit()
index c9a314212814eac926dc59919c0bf70858e2e0e8..f958bc1cf5e8a47ac5d52c58dc086aafa94c8375 100644 (file)
@@ -280,7 +280,7 @@ class DependencyTwoParentTest(fixtures.MappedTest):
         mapper(D, tbl_d, properties=dict(b_row=relationship(B)))
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, C, B, D = (
             cls.classes.A,
             cls.classes.C,
@@ -288,7 +288,7 @@ class DependencyTwoParentTest(fixtures.MappedTest):
             cls.classes.D,
         )
 
-        session = create_session()
+        session = create_session(connection)
         a = A(name="a1")
         b = B(name="b1")
         c = C(name="c1", a_row=a)
@@ -3608,9 +3608,9 @@ class FunctionAsPrimaryJoinTest(fixtures.DeclarativeMappedTest):
             )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Venue = cls.classes.Venue
-        s = Session()
+        s = Session(connection)
         s.add_all(
             [
                 Venue(name="parent1"),
@@ -3688,9 +3688,9 @@ class RemoteForeignBetweenColsTest(fixtures.DeclarativeMappedTest):
             ip_addr = Column(Integer, primary_key=True)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Network, Address = cls.classes.Network, cls.classes.Address
-        s = Session(testing.db)
+        s = Session(connection)
 
         s.add_all(
             [
@@ -4309,9 +4309,9 @@ class SecondaryNestedJoinTest(
         mapper(D, d)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, B, C, D = cls.classes.A, cls.classes.B, cls.classes.C, cls.classes.D
-        sess = Session()
+        sess = Session(connection)
         a1, a2, a3, a4 = A(name="a1"), A(name="a2"), A(name="a3"), A(name="a4")
         b1, b2, b3, b4 = B(name="b1"), B(name="b2"), B(name="b3"), B(name="b4")
         c1, c2, c3, c4 = C(name="c1"), C(name="c2"), C(name="c3"), C(name="c4")
@@ -5647,10 +5647,10 @@ class SecondaryIncludesLocalColsTest(fixtures.MappedTest):
         mapper(B, b)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, B = cls.classes("A", "B")
 
-        s = Session()
+        s = Session(connection)
         s.add_all(
             [
                 A(id=1, b_ids="1"),
index 5039ab0a8ac0d25f534d9d9880479c28c724f8ef..d89fb4949b0206e0dd024a6cc8d9c92dbf503fbe 100644 (file)
@@ -1685,7 +1685,7 @@ class BaseRelationFromJoinedSubclassTest(_Polymorphic):
         mapper(Paperwork, paperwork)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
 
         e1 = Engineer(primary_language="java")
         e2 = Engineer(primary_language="c++")
@@ -1694,7 +1694,7 @@ class BaseRelationFromJoinedSubclassTest(_Polymorphic):
             Paperwork(description="tps report #2"),
         ]
         e2.paperwork = [Paperwork(description="tps report #3")]
-        sess = create_session()
+        sess = create_session(connection)
         sess.add_all([e1, e2])
         sess.flush()
 
@@ -1992,7 +1992,7 @@ class HeterogeneousSubtypesTest(fixtures.DeclarativeMappedTest):
             name = Column(String(50))
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Company, Programmer, Manager, GolfSwing, Language = cls.classes(
             "Company", "Programmer", "Manager", "GolfSwing", "Language"
         )
@@ -2016,7 +2016,7 @@ class HeterogeneousSubtypesTest(fixtures.DeclarativeMappedTest):
                 ),
             ],
         )
-        sess = Session()
+        sess = Session(connection)
         sess.add_all([c1, c2])
         sess.commit()
 
@@ -2118,10 +2118,10 @@ class TupleTest(fixtures.DeclarativeMappedTest):
             )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, B = cls.classes("A", "B")
 
-        session = Session()
+        session = Session(connection)
         session.add_all(
             [
                 A(id1=i, id2=i + 2, bs=[B(id=(i * 6) + j) for j in range(6)])
@@ -2226,10 +2226,10 @@ class ChunkingTest(fixtures.DeclarativeMappedTest):
             a = relationship("A", back_populates="bs")
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, B = cls.classes("A", "B")
 
-        session = Session()
+        session = Session(connection)
         session.add_all(
             [
                 A(id=i, bs=[B(id=(i * 6) + j) for j in range(1, 6)])
@@ -2460,9 +2460,9 @@ class SubRelationFromJoinedSubclassMultiLevelTest(_Polymorphic):
         mapper(MachineType, machine_type)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         c1 = cls._fixture()
-        sess = create_session()
+        sess = create_session(connection)
         sess.add(c1)
         sess.flush()
 
@@ -2838,10 +2838,10 @@ class SelfRefInheritanceAliasedTest(
             __mapper_args__ = {"polymorphic_identity": "bar"}
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Foo, Bar = cls.classes("Foo", "Bar")
 
-        session = Session()
+        session = Session(connection)
         target = Bar(id=1)
         b1 = Bar(id=2, foo=Foo(id=3, foo=target))
         session.add(b1)
@@ -2943,12 +2943,12 @@ class TestExistingRowPopulation(fixtures.DeclarativeMappedTest):
             id = Column(Integer, primary_key=True)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, A2, B, C1o2m, C2o2m, C1m2o, C2m2o = cls.classes(
             "A", "A2", "B", "C1o2m", "C2o2m", "C1m2o", "C2m2o"
         )
 
-        s = Session()
+        s = Session(connection)
 
         b = B(
             c1_o2m=[C1o2m()], c2_o2m=[C2o2m()], c1_m2o=C1m2o(), c2_m2o=C2m2o()
@@ -3025,10 +3025,10 @@ class SingleInhSubclassTest(
             user_id = Column(Integer, ForeignKey("user.id"))
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         EmployerUser, Role = cls.classes("EmployerUser", "Role")
 
-        s = Session()
+        s = Session(connection)
         s.add(EmployerUser(roles=[Role(), Role(), Role()]))
         s.commit()
 
@@ -3076,10 +3076,10 @@ class MissingForeignTest(
             y = Column(Integer)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, B = cls.classes("A", "B")
 
-        s = Session()
+        s = Session(connection)
         b1, b2 = B(id=1, x=5, y=9), B(id=2, x=10, y=8)
         s.add_all(
             [
@@ -3130,10 +3130,10 @@ class M2OWDegradeTest(
             y = Column(Integer)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, B = cls.classes("A", "B")
 
-        s = Session()
+        s = Session(connection)
         b1, b2 = B(id=1, x=5, y=9), B(id=2, x=10, y=8)
         s.add_all(
             [
@@ -3369,11 +3369,11 @@ class SameNamePolymorphicTest(fixtures.DeclarativeMappedTest):
             parent = relationship("ParentB", back_populates="children")
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         ParentA, ParentB, ChildA, ChildB = cls.classes(
             "ParentA", "ParentB", "ChildA", "ChildB"
         )
-        session = Session()
+        session = Session(connection)
         parent_a = ParentA(id=1)
         parent_b = ParentB(id=2)
         for i in range(10):
index f3fdfd3dcda862489ff0964440a9b33c81751cd5..c2afe6f99745106d4cc450543605421da2c0ee1c 100644 (file)
@@ -1637,7 +1637,7 @@ class BaseRelationFromJoinedSubclassTest(_Polymorphic):
         mapper(Page, pages)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
 
         e1 = Engineer(primary_language="java")
         e2 = Engineer(primary_language="c++")
@@ -1658,7 +1658,7 @@ class BaseRelationFromJoinedSubclassTest(_Polymorphic):
             ),
         ]
         e2.paperwork = [Paperwork(description="tps report #3")]
-        sess = create_session()
+        sess = create_session(connection)
         sess.add_all([e1, e2])
         sess.flush()
 
@@ -2128,9 +2128,9 @@ class SubRelationFromJoinedSubclassMultiLevelTest(_Polymorphic):
         mapper(MachineType, machine_type)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         c1 = cls._fixture()
-        sess = create_session()
+        sess = create_session(connection)
         sess.add(c1)
         sess.flush()
 
@@ -2782,7 +2782,7 @@ class SubqueryloadDistinctTest(
             movie_id = Column(Integer, ForeignKey("movie.id"))
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Movie = cls.classes.Movie
         Director = cls.classes.Director
         DirectorPhoto = cls.classes.DirectorPhoto
@@ -2794,7 +2794,7 @@ class SubqueryloadDistinctTest(
             Movie(title="Manhattan", credits=[Credit(), Credit()]),
             Movie(title="Sweet and Lowdown", credits=[Credit()]),
         ]
-        sess = create_session()
+        sess = create_session(connection)
         sess.add_all([d])
         sess.flush()
 
@@ -2958,11 +2958,11 @@ class JoinedNoLoadConflictTest(fixtures.DeclarativeMappedTest):
             )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Parent = cls.classes.Parent
         Child = cls.classes.Child
 
-        s = Session()
+        s = Session(connection)
         s.add(Parent(name="parent", children=[Child(name="c1")]))
         s.commit()
 
@@ -3008,10 +3008,10 @@ class SelfRefInheritanceAliasedTest(
             __mapper_args__ = {"polymorphic_identity": "bar"}
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Foo, Bar = cls.classes("Foo", "Bar")
 
-        session = Session()
+        session = Session(connection)
         target = Bar(id=1)
         b1 = Bar(id=2, foo=Foo(id=3, foo=target))
         session.add(b1)
@@ -3117,12 +3117,12 @@ class TestExistingRowPopulation(fixtures.DeclarativeMappedTest):
             id = Column(Integer, primary_key=True)
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         A, A2, B, C1o2m, C2o2m, C1m2o, C2m2o = cls.classes(
             "A", "A2", "B", "C1o2m", "C2o2m", "C1m2o", "C2m2o"
         )
 
-        s = Session()
+        s = Session(connection)
 
         b = B(
             c1_o2m=[C1o2m()], c2_o2m=[C2o2m()], c1_m2o=C1m2o(), c2_m2o=C2m2o()
index 4384fa67eb8d124785a07673d2a4759ad836af09..bec4ecd92928fc6ded183eb1c747d179380e9c55 100644 (file)
@@ -55,16 +55,17 @@ class UpdateDeleteTest(fixtures.MappedTest):
             pass
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         users = cls.tables.users
 
-        users.insert().execute(
+        connection.execute(
+            users.insert(),
             [
                 dict(id=1, name="john", age_int=25),
                 dict(id=2, name="jack", age_int=47),
                 dict(id=3, name="jill", age_int=29),
                 dict(id=4, name="jane", age_int=37),
-            ]
+            ],
         )
 
     @classmethod
@@ -744,26 +745,28 @@ class UpdateDeleteIgnoresLoadersTest(fixtures.MappedTest):
             pass
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         users = cls.tables.users
 
-        users.insert().execute(
+        connection.execute(
+            users.insert(),
             [
                 dict(id=1, name="john", age=25),
                 dict(id=2, name="jack", age=47),
                 dict(id=3, name="jill", age=29),
                 dict(id=4, name="jane", age=37),
-            ]
+            ],
         )
 
         documents = cls.tables.documents
 
-        documents.insert().execute(
+        connection.execute(
+            documents.insert(),
             [
                 dict(id=1, user_id=1, title="foo"),
                 dict(id=2, user_id=1, title="bar"),
                 dict(id=3, user_id=2, title="baz"),
-            ]
+            ],
         )
 
     @classmethod
@@ -863,16 +866,17 @@ class UpdateDeleteFromTest(fixtures.MappedTest):
             pass
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         users = cls.tables.users
 
-        users.insert().execute(
-            [dict(id=1), dict(id=2), dict(id=3), dict(id=4)]
+        connection.execute(
+            users.insert(), [dict(id=1), dict(id=2), dict(id=3), dict(id=4)]
         )
 
         documents = cls.tables.documents
 
-        documents.insert().execute(
+        connection.execute(
+            documents.insert(),
             [
                 dict(id=1, user_id=1, title="foo"),
                 dict(id=2, user_id=1, title="bar"),
@@ -880,7 +884,7 @@ class UpdateDeleteFromTest(fixtures.MappedTest):
                 dict(id=4, user_id=2, title="hoho"),
                 dict(id=5, user_id=3, title="lala"),
                 dict(id=6, user_id=3, title="bleh"),
-            ]
+            ],
         )
 
     @classmethod
@@ -1141,13 +1145,13 @@ class InheritTest(fixtures.DeclarativeMappedTest):
             manager_name = Column(String(50))
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         Engineer, Person, Manager = (
             cls.classes.Engineer,
             cls.classes.Person,
             cls.classes.Manager,
         )
-        s = Session(testing.db)
+        s = Session(connection)
         s.add_all(
             [
                 Engineer(name="e1", engineer_name="e1"),
index 0a50a6356c39f2622c2c961e212e282b08a6916e..fd5aec503633071751b168a43e98645096de17d3 100644 (file)
@@ -1446,11 +1446,12 @@ class InsertFromSelectTest(fixtures.TablesTest):
         Table("data", metadata, Column("x", Integer), Column("y", Integer))
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         data = cls.tables.data
 
-        with testing.db.connect() as conn:
-            conn.execute(data.insert(), [{"x": 2, "y": 5}, {"x": 7, "y": 12}])
+        connection.execute(
+            data.insert(), [{"x": 2, "y": 5}, {"x": 7, "y": 12}]
+        )
 
     @testing.provide_metadata
     def test_insert_from_select_override_defaults(self, connection):
index 13d4cd1547dcf66b11e055b8fb45609c100269b0..43e906032f79e1f394713fe0715b2cd06dc40109 100644 (file)
@@ -879,21 +879,19 @@ class KeyTargetingTest(fixtures.TablesTest):
             )
 
     @classmethod
-    def insert_data(cls):
-        with testing.db.connect() as conn:
-            conn.execute(cls.tables.keyed1.insert(), dict(b="a1", q="c1"))
-            conn.execute(cls.tables.keyed2.insert(), dict(a="a2", b="b2"))
-            conn.execute(cls.tables.keyed3.insert(), dict(a="a3", d="d3"))
-            conn.execute(cls.tables.keyed4.insert(), dict(b="b4", q="q4"))
-            conn.execute(cls.tables.content.insert(), type="t1")
-
-            if testing.requires.schemas.enabled:
-                conn.execute(
-                    cls.tables[
-                        "%s.wschema" % testing.config.test_schema
-                    ].insert(),
-                    dict(b="a1", q="c1"),
-                )
+    def insert_data(cls, connection):
+        conn = connection
+        conn.execute(cls.tables.keyed1.insert(), dict(b="a1", q="c1"))
+        conn.execute(cls.tables.keyed2.insert(), dict(a="a2", b="b2"))
+        conn.execute(cls.tables.keyed3.insert(), dict(a="a3", d="d3"))
+        conn.execute(cls.tables.keyed4.insert(), dict(b="b4", q="q4"))
+        conn.execute(cls.tables.content.insert(), type="t1")
+
+        if testing.requires.schemas.enabled:
+            conn.execute(
+                cls.tables["%s.wschema" % testing.config.test_schema].insert(),
+                dict(b="a1", q="c1"),
+            )
 
     def test_column_label_overlap_fallback(self, connection):
         content, bar = self.tables.content, self.tables.bar
@@ -1109,15 +1107,14 @@ class ResultProxyTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         users = cls.tables.users
 
-        with testing.db.connect() as conn:
-            conn.execute(
-                users.insert(),
-                dict(user_id=1, user_name="john"),
-                dict(user_id=2, user_name="jack"),
-            )
+        connection.execute(
+            users.insert(),
+            dict(user_id=1, user_name="john"),
+            dict(user_id=2, user_name="jack"),
+        )
 
     def test_column_accessor_textual_select(self, connection):
         users = self.tables.users
@@ -1481,12 +1478,10 @@ class PositionalTextTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        with testing.db.connect() as conn:
-            conn.execute(
-                cls.tables.text1.insert(),
-                [dict(a="a1", b="b1", c="c1", d="d1")],
-            )
+    def insert_data(cls, connection):
+        connection.execute(
+            cls.tables.text1.insert(), [dict(a="a1", b="b1", c="c1", d="d1")],
+        )
 
     def test_anon_aliased_overlapping(self, connection):
         text1 = self.tables.text1
index f8d245228acc17dfe75e2a85c7d821706e5640d4..470417dd3c2c29fef9e2a057496db33bcf9f4ba0 100644 (file)
@@ -1406,21 +1406,19 @@ class KeyTargetingTest(fixtures.TablesTest):
             )
 
     @classmethod
-    def insert_data(cls):
-        with testing.db.begin() as conn:
-            conn.execute(cls.tables.keyed1.insert(), dict(b="a1", q="c1"))
-            conn.execute(cls.tables.keyed2.insert(), dict(a="a2", b="b2"))
-            conn.execute(cls.tables.keyed3.insert(), dict(a="a3", d="d3"))
-            conn.execute(cls.tables.keyed4.insert(), dict(b="b4", q="q4"))
-            conn.execute(cls.tables.content.insert(), dict(type="t1"))
-
-            if testing.requires.schemas.enabled:
-                conn.execute(
-                    cls.tables[
-                        "%s.wschema" % testing.config.test_schema
-                    ].insert(),
-                    dict(b="a1", q="c1"),
-                )
+    def insert_data(cls, connection):
+        conn = connection
+        conn.execute(cls.tables.keyed1.insert(), dict(b="a1", q="c1"))
+        conn.execute(cls.tables.keyed2.insert(), dict(a="a2", b="b2"))
+        conn.execute(cls.tables.keyed3.insert(), dict(a="a3", d="d3"))
+        conn.execute(cls.tables.keyed4.insert(), dict(b="b4", q="q4"))
+        conn.execute(cls.tables.content.insert(), dict(type="t1"))
+
+        if testing.requires.schemas.enabled:
+            conn.execute(
+                cls.tables["%s.wschema" % testing.config.test_schema].insert(),
+                dict(b="a1", q="c1"),
+            )
 
     @testing.requires.schemas
     def test_keyed_accessor_wschema(self, connection):
@@ -1835,12 +1833,10 @@ class PositionalTextTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        with testing.db.connect() as conn:
-            conn.execute(
-                cls.tables.text1.insert(),
-                [dict(a="a1", b="b1", c="c1", d="d1")],
-            )
+    def insert_data(cls, connection):
+        connection.execute(
+            cls.tables.text1.insert(), [dict(a="a1", b="b1", c="c1", d="d1")],
+        )
 
     def test_via_column(self, connection):
         c1, c2, c3, c4 = column("q"), column("p"), column("r"), column("d")
@@ -2053,12 +2049,11 @@ class AlternateResultProxyTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        with cls.engine.connect() as conn:
-            conn.execute(
-                cls.tables.test.insert(),
-                [{"x": i, "y": "t_%d" % i} for i in range(1, 12)],
-            )
+    def insert_data(cls, connection):
+        connection.execute(
+            cls.tables.test.insert(),
+            [{"x": i, "y": "t_%d" % i} for i in range(1, 12)],
+        )
 
     @contextmanager
     def _proxy_fixture(self, cls):