]> 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:16:12 +0000 (11:16 -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
(cherry picked from commit 5c010c097352c783729e210018b95130ef94a926)

45 files changed:
lib/sqlalchemy/testing/fixtures.py
lib/sqlalchemy/testing/suite/test_cte.py
lib/sqlalchemy/testing/suite/test_results.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_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 012de7911d9e08266a46fb09b9ebc0733fe0abdc..2dbb540f9c850aa0406bd8874c3a7d7ba11eeef3 100644 (file)
@@ -36,8 +36,8 @@ class CTETest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        config.db.execute(
+    def insert_data(cls, connection):
+        connection.execute(
             cls.tables.some_table.insert(),
             [
                 {"id": 1, "data": "d1", "parent_id": None},
index 125fefce98cad3cf7ba9541e8d91b5452821eddf..78b2430a1f0665655afcdd509446f201d89431a8 100644 (file)
@@ -36,8 +36,8 @@ class RowFetchTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        config.db.execute(
+    def insert_data(cls, connection):
+        connection.execute(
             cls.tables.plain_pk.insert(),
             [
                 {"id": 1, "data": "d1"},
@@ -46,7 +46,7 @@ class RowFetchTest(fixtures.TablesTest):
             ],
         )
 
-        config.db.execute(
+        connection.execute(
             cls.tables.has_dates.insert(),
             [{"id": 1, "today": datetime.datetime(2006, 5, 12, 12, 0, 0)}],
         )
index 06f1aa65c648efd8f5bec3be9e8f8f46a819d218..d29449a5194530ff85bbeaaf645762fa03007e63 100644 (file)
@@ -35,8 +35,8 @@ class CollateTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        config.db.execute(
+    def insert_data(cls, connection):
+        connection.execute(
             cls.tables.some_table.insert(),
             [
                 {"id": 1, "data": "collate data1"},
@@ -83,8 +83,8 @@ class OrderByLabelTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        config.db.execute(
+    def insert_data(cls, connection):
+        connection.execute(
             cls.tables.some_table.insert(),
             [
                 {"id": 1, "x": 1, "y": 2, "q": "q1", "p": "p3"},
@@ -155,8 +155,8 @@ class LimitOffsetTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        config.db.execute(
+    def insert_data(cls, connection):
+        connection.execute(
             cls.tables.some_table.insert(),
             [
                 {"id": 1, "x": 1, "y": 2},
@@ -250,8 +250,8 @@ class CompoundSelectTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        config.db.execute(
+    def insert_data(cls, connection):
+        connection.execute(
             cls.tables.some_table.insert(),
             [
                 {"id": 1, "x": 1, "y": 2},
@@ -377,8 +377,8 @@ class ExpandingBoundInTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        config.db.execute(
+    def insert_data(cls, connection):
+        connection.execute(
             cls.tables.some_table.insert(),
             [
                 {"id": 1, "x": 1, "y": 2, "z": "z1"},
@@ -565,8 +565,8 @@ class LikeFunctionsTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        config.db.execute(
+    def insert_data(cls, connection):
+        connection.execute(
             cls.tables.some_table.insert(),
             [
                 {"id": 1, "data": "abcdefg"},
@@ -676,12 +676,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 97bdf0ad76d2a32a62d09845427361db623417da..25f9d4716382845eb18cd019053e14b44b3d6169 100644 (file)
@@ -21,8 +21,8 @@ class SimpleUpdateDeleteTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        config.db.execute(
+    def insert_data(cls, connection):
+        connection.execute(
             cls.tables.plain_pk.insert(),
             [
                 {"id": 1, "data": "d1"},
index 2b07f2539055a2ff64dc1a4cfe8732a99eee2324..6b48c556b2df4bba681a0467148567821392c1b0 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
@@ -183,13 +185,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,
@@ -197,7 +201,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):
@@ -286,9 +290,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(
@@ -352,9 +356,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(
@@ -654,9 +658,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()
 
@@ -785,9 +789,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()])],
@@ -1151,9 +1155,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 3537c3220dcef1edf9dd93b285a7306ff97c3d8f..948be0797719b2aaa370f8f931ace847e0729f32 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 e492f1e17f2e3da7809bdccfe78e9d964fe6430b..35d3c0f84d0d86b2140dcfbada23c80f897ecfcf 100644 (file)
@@ -231,9 +231,9 @@ class AnyAllTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         stuff = cls.tables.stuff
-        testing.db.execute(
+        connection.execute(
             stuff.insert(),
             [
                 {"id": 1, "value": 1},
index e664ba50ec2e79deed9fdd5e60c213f28be6312c..4c61f08b44f3b53097567538be679fa255f35791 100644 (file)
@@ -908,7 +908,7 @@ class LOBFetchTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         cls.data = data = [
             dict(
                 id=i,
@@ -918,7 +918,7 @@ class LOBFetchTest(fixtures.TablesTest):
             for i in range(1, 20)
         ]
 
-        testing.db.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(
@@ -928,7 +928,7 @@ class LOBFetchTest(fixtures.TablesTest):
             cls.stream = stream = file_.read(12000)
 
         for i in range(1, 11):
-            binary_table.insert().execute(id=i, data=stream)
+            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 40cd85c79814788b0dc36cfe860c3a4a3b1621b8..01edf6595c2c46f0b50396d3eefc5d0e20e99afc 100644 (file)
@@ -950,14 +950,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 61fb9d67940e4e86e33acd3c46956535552a6040..6b46a60044730007882d21a09b975b5f5ced5939 100644 (file)
@@ -79,20 +79,24 @@ class FloatCoercionTest(fixtures.TablesTest, AssertsExecutionResults):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         data_table = cls.tables.data_table
 
-        data_table.insert().execute(
-            {"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},
+                ]
+            )
         )
 
     @testing.fails_on(
index 264c4839c9cb0168e7dd49edf2d203ae832cc1ed..336c919a887fe60c27ce574ef9c573d6e0df9294 100644 (file)
@@ -2181,7 +2181,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 [
@@ -2192,8 +2192,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 [
@@ -2203,7 +2204,7 @@ def _produce_test(inline, stringbased):
                         (4, 8, "ed@lala.com"),
                         (5, 9, "fred@fred.com"),
                     ]
-                ]
+                ],
             )
 
         def test_aliased_join(self):
index e7cc6251bbacb1273060fd0d13b0c735b481a6d1..2054e023cd3407a970b94de5bbb429c161ee5ef1 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
@@ -1614,7 +1613,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,
@@ -1622,7 +1621,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)
@@ -1649,7 +1648,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())
@@ -3440,10 +3441,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 16694c86f5dfa5eb16d3cb9b1cd91b31592eb734..a3d1d957fa096dc0cb6bba6521c1563ddb060667 100644 (file)
@@ -512,9 +512,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 5cffa34066fc665d6aeffd401e3e7e18e8cf69f1..4756ae78adcf7d24cbb45ec0be64362ab94d22ba 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 dda1ce5758f4af5e7b2a36444d3ce27538039630..3fa5c998702304a135cc1bd69227685339bf0ea2 100644 (file)
@@ -1249,11 +1249,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 5a7b549ac830fabb0b87780e4230db8964865256..8f1c6d014f4f85c32fbceb0111f43e570bfaf5af 100644 (file)
@@ -159,10 +159,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"),
@@ -1972,14 +1972,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)
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 f450b760df34b2dd9864c73ae2ca55c4ae71d162..f3d08fb423c18f6d84f44e4100e8597c4d8a8924 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 00a240cdcb6fce4761b58aac791dd98e1eb18d31..11449290609262c232f8f6bf01732c588474f4ff 100644 (file)
@@ -316,7 +316,7 @@ class RoundTripTest(PolymorphTest):
         )
 
     @classmethod
-    def insert_data(cls):
+    def insert_data(cls, connection):
         redefine_colprop = cls.redefine_colprop
         include_base = cls.include_base
 
@@ -354,7 +354,7 @@ class RoundTripTest(PolymorphTest):
             ),
         ]
 
-        session = Session()
+        session = Session(connection)
         c = Company(name="company1")
         c.employees = employees
         session.add(c)
index 8e09dfc147d922a6653ff31de8b790da90430dee..880cc5f913d42cbb93f436c0f08d76d1ac5539e1 100644 (file)
@@ -45,8 +45,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 851ad60b872958005f5c6e7b89f57f6cd7a84ae6..48c71209f0d28a204b772ca41a7950a289454162 100644 (file)
@@ -573,7 +573,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")
@@ -581,7 +581,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()
@@ -899,13 +899,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)
@@ -1078,11 +1078,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")],
@@ -1264,12 +1264,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])])
@@ -1435,10 +1435,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()
 
@@ -1781,7 +1781,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"
         )
@@ -1791,7 +1791,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()
 
@@ -2726,9 +2726,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 a33ea5ecb9b13605c93322c5f79614e46c92d6f0..389cc4fa4d75912adb5b77e48cbda2e15d527dd8 100644 (file)
@@ -1259,11 +1259,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 aec9ee5e46f90dd7d84384faeb83fbfaeea2ca96..14fecf74a07938239c2937cd7f522d39a1467b27 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 21534d6bc9907d804c0c7d845a651bd32ffbeb1a..f80b7040cc21515b4dc5385022af917ffaa53223 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 5f4519bcf7ebcc4a4114efc2ebaddcc3c2daad71..611f6e176359b645e56c6e2288a2892f58022252 100644 (file)
@@ -1562,7 +1562,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,
@@ -1572,7 +1572,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 5b97308bebb823f82eff226a568f9811e480c179..03bd70285c07ce79b4baeaa5aa382b4d521bd6ad 100644 (file)
@@ -1188,10 +1188,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"),
@@ -1651,9 +1651,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(
             [
index a5953452ae0a992c1d2dc1ae4a459e8450f5de55..cbf2c4bfbfe7b56cf874bb5698dc1265ec24939a 100644 (file)
@@ -2995,8 +2995,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()
 
@@ -3223,8 +3223,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()
 
@@ -4200,25 +4200,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):
@@ -4818,16 +4827,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)},
@@ -5544,9 +5555,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 846f6241ba412e8e822bef2d6bf1133ec978ff18..1774bbc546fd81f1ae9a7e3a0f77a397b04455e6 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 ed4950a06cbd8c45eb1b448af43966c14b054c68..fafaba48424c739d23579ebd689a1cc48e03b37f 100644 (file)
@@ -1302,15 +1302,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 72358553ed342b62f89227d79c88d426a697af3f..a586d3ada3708a2fb2efce477c46ea1abaec0357 100644 (file)
@@ -803,10 +803,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"),
@@ -3619,8 +3619,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 eca4068b4ef6e700c91c6636a7c14b15c1ba3588..aaa96ae4ad8cf1b7e2416eeb9729a5832f89f583 100644 (file)
@@ -3092,10 +3092,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"))
@@ -3802,7 +3802,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,
@@ -3822,7 +3822,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 3566a5ca729649a8148841b93260fa12f03812d3..df2452adfd0fbba5d54b36f4a8ea386eea3b249d 100644 (file)
@@ -1246,16 +1246,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 72e428efcd120797a8fd2d254fc412f494ea63d6..0aed3a5c183d06469a7dc270eb388b1895b48781 100644 (file)
@@ -2841,7 +2841,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,
@@ -2849,7 +2849,8 @@ class SecondaryOptionsTest(fixtures.MappedTest):
             cls.tables.related,
         )
 
-        base.insert().execute(
+        connection.execute(
+            base.insert(),
             [
                 {"id": 1, "type": "child1"},
                 {"id": 2, "type": "child1"},
@@ -2857,18 +2858,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):
@@ -3029,13 +3032,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 89fb4d6e178fe6c83d05e6349a4999287aa5003d..b52f4ddb1cb6383a4234f8f0a13935440976390d 100644 (file)
@@ -1662,9 +1662,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 59391b0fc6eb927d60f8d94058d50e31b9d12b24..bf7ee2828675feeae65c6308989adc3d72fd97ca 100644 (file)
@@ -564,8 +564,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()
@@ -1022,8 +1022,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 4b7d4d18e55f20c7b4e1dd8fe8d0852f11257d9e..6cec819ce75ebb3c3d7323ad61dc89baeddc6acb 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)
@@ -3468,9 +3468,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"),
@@ -3548,9 +3548,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(
             [
@@ -4169,9 +4169,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")
@@ -5507,10 +5507,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 f3e0baa1fb523fd1ff59a76788d71bc203dfbd17..d74c52bfef4475d4b3a596f137259c7bc2a5b75f 100644 (file)
@@ -1675,7 +1675,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++")
@@ -1684,7 +1684,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()
 
@@ -1982,7 +1982,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"
         )
@@ -2006,7 +2006,7 @@ class HeterogeneousSubtypesTest(fixtures.DeclarativeMappedTest):
                 ),
             ],
         )
-        sess = Session()
+        sess = Session(connection)
         sess.add_all([c1, c2])
         sess.commit()
 
@@ -2108,10 +2108,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)])
@@ -2216,10 +2216,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)])
@@ -2450,9 +2450,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()
 
@@ -2828,10 +2828,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)
@@ -2933,12 +2933,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()
@@ -3015,10 +3015,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()
 
@@ -3066,10 +3066,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(
             [
@@ -3120,10 +3120,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(
             [
@@ -3359,11 +3359,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 ddd8306775b3c9c61335150a880fe1b18c14c931..61ff11ec9c5b68ea70708ced6d6d555db6c24251 100644 (file)
@@ -1633,7 +1633,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++")
@@ -1654,7 +1654,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()
 
@@ -2124,9 +2124,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()
 
@@ -2778,7 +2778,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
@@ -2790,7 +2790,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()
 
@@ -2954,11 +2954,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()
 
@@ -3004,10 +3004,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)
@@ -3113,12 +3113,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 b90202f33f2742358f9cad0f484ee4649aa92dfa..46bb870621d5bb38d8f46d2f438a9a4fb3e551f5 100644 (file)
@@ -56,16 +56,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
@@ -743,26 +744,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
@@ -862,16 +865,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"),
@@ -879,7 +883,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
@@ -1140,13 +1144,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 b7454cf198f9f6f402f5a230cc977296294d569e..f72f446798e695312ccfcdbcfe2f24b2c49bcbdc 100644 (file)
@@ -1449,11 +1449,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 5987c77467f33630928e1e9443db9321d640e16c..db7c1f47b22511142f08b05de947424f83e25918 100644 (file)
@@ -1250,17 +1250,19 @@ class KeyTargetingTest(fixtures.TablesTest):
             )
 
     @classmethod
-    def insert_data(cls):
-        cls.tables.keyed1.insert().execute(dict(b="a1", q="c1"))
-        cls.tables.keyed2.insert().execute(dict(a="a2", b="b2"))
-        cls.tables.keyed3.insert().execute(dict(a="a3", d="d3"))
-        cls.tables.keyed4.insert().execute(dict(b="b4", q="q4"))
-        cls.tables.content.insert().execute(type="t1")
+    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:
-            cls.tables[
-                "%s.wschema" % testing.config.test_schema
-            ].insert().execute(dict(b="a1", q="c1"))
+            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):
@@ -1472,9 +1474,9 @@ class PositionalTextTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        cls.tables.text1.insert().execute(
-            [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):
@@ -1651,8 +1653,8 @@ class AlternateResultProxyTest(fixtures.TablesTest):
         )
 
     @classmethod
-    def insert_data(cls):
-        cls.engine.execute(
+    def insert_data(cls, connection):
+        connection.execute(
             cls.tables.test.insert(),
             [{"x": i, "y": "t_%d" % i} for i in range(1, 12)],
         )