summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2020-04-15 18:31:30 +0000
committerGerrit Code Review <gerrit@bbpush.zzzcomputing.com>2020-04-15 18:31:30 +0000
commitbd303b10e2bf69169f07447c7272fc71ac931f10 (patch)
tree7d2b6b21fbf880062e0bfddd31c85382bf11ccf1
parent447c0750e1f739c4db1d0d20de182c297dc86e36 (diff)
parent8725d89abaf1a6ce870e71fbf1a4962dc4899204 (diff)
downloadsqlalchemy-bd303b10e2bf69169f07447c7272fc71ac931f10.tar.gz
Merge "Pass connection to TablesTest.insert_data()"
-rw-r--r--lib/sqlalchemy/testing/fixtures.py8
-rw-r--r--lib/sqlalchemy/testing/suite/test_cte.py23
-rw-r--r--lib/sqlalchemy/testing/suite/test_deprecations.py22
-rw-r--r--lib/sqlalchemy/testing/suite/test_results.py28
-rw-r--r--lib/sqlalchemy/testing/suite/test_rowcount.py12
-rw-r--r--lib/sqlalchemy/testing/suite/test_select.py193
-rw-r--r--lib/sqlalchemy/testing/suite/test_update_delete.py20
-rw-r--r--test/aaa_profiling/test_orm.py40
-rw-r--r--test/dialect/mysql/test_for_update.py4
-rw-r--r--test/dialect/mysql/test_query.py23
-rw-r--r--test/dialect/oracle/test_types.py10
-rw-r--r--test/dialect/postgresql/test_query.py4
-rw-r--r--test/dialect/postgresql/test_types.py33
-rw-r--r--test/ext/declarative/test_basic.py9
-rw-r--r--test/ext/test_associationproxy.py13
-rw-r--r--test/ext/test_horizontal_shard.py4
-rw-r--r--test/ext/test_hybrid.py4
-rw-r--r--test/ext/test_serializer.py9
-rw-r--r--test/orm/inheritance/_poly_fixtures.py4
-rw-r--r--test/orm/inheritance/test_assorted_poly.py4
-rw-r--r--test/orm/inheritance/test_basic.py22
-rw-r--r--test/orm/inheritance/test_concrete.py8
-rw-r--r--test/orm/inheritance/test_poly_loading.py8
-rw-r--r--test/orm/inheritance/test_poly_persistence.py4
-rw-r--r--test/orm/inheritance/test_polymorphic_rel.py4
-rw-r--r--test/orm/inheritance/test_relationship.py28
-rw-r--r--test/orm/inheritance/test_single.py4
-rw-r--r--test/orm/test_ac_relationships.py8
-rw-r--r--test/orm/test_assorted_eager.py4
-rw-r--r--test/orm/test_bundle.py4
-rw-r--r--test/orm/test_cascade.py4
-rw-r--r--test/orm/test_deferred.py12
-rw-r--r--test/orm/test_eager_relations.py63
-rw-r--r--test/orm/test_events.py4
-rw-r--r--test/orm/test_expire.py8
-rw-r--r--test/orm/test_froms.py8
-rw-r--r--test/orm/test_joins.py8
-rw-r--r--test/orm/test_lazy_relations.py8
-rw-r--r--test/orm/test_mapper.py27
-rw-r--r--test/orm/test_merge.py4
-rw-r--r--test/orm/test_of_type.py8
-rw-r--r--test/orm/test_relationships.py20
-rw-r--r--test/orm/test_selectin_relations.py44
-rw-r--r--test/orm/test_subquery_relations.py24
-rw-r--r--test/orm/test_update_delete.py34
-rw-r--r--test/sql/test_defaults.py7
-rw-r--r--test/sql/test_deprecations.py51
-rw-r--r--test/sql/test_resultset.py49
48 files changed, 475 insertions, 469 deletions
diff --git a/lib/sqlalchemy/testing/fixtures.py b/lib/sqlalchemy/testing/fixtures.py
index 4f6083401..e5e6c42fc 100644
--- a/lib/sqlalchemy/testing/fixtures.py
+++ b/lib/sqlalchemy/testing/fixtures.py
@@ -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):
diff --git a/lib/sqlalchemy/testing/suite/test_cte.py b/lib/sqlalchemy/testing/suite/test_cte.py
index fab457606..1ee6cac10 100644
--- a/lib/sqlalchemy/testing/suite/test_cte.py
+++ b/lib/sqlalchemy/testing/suite/test_cte.py
@@ -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
diff --git a/lib/sqlalchemy/testing/suite/test_deprecations.py b/lib/sqlalchemy/testing/suite/test_deprecations.py
index 126d82fe9..8c25616a8 100644
--- a/lib/sqlalchemy/testing/suite/test_deprecations.py
+++ b/lib/sqlalchemy/testing/suite/test_deprecations.py
@@ -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)
diff --git a/lib/sqlalchemy/testing/suite/test_results.py b/lib/sqlalchemy/testing/suite/test_results.py
index 0cff7b61d..2eb986c74 100644
--- a/lib/sqlalchemy/testing/suite/test_results.py
+++ b/lib/sqlalchemy/testing/suite/test_results.py
@@ -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(
diff --git a/lib/sqlalchemy/testing/suite/test_rowcount.py b/lib/sqlalchemy/testing/suite/test_rowcount.py
index ae189bc79..06945ff2a 100644
--- a/lib/sqlalchemy/testing/suite/test_rowcount.py
+++ b/lib/sqlalchemy/testing/suite/test_rowcount.py
@@ -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
diff --git a/lib/sqlalchemy/testing/suite/test_select.py b/lib/sqlalchemy/testing/suite/test_select.py
index 23f78961f..c1f77a7c1 100644
--- a/lib/sqlalchemy/testing/suite/test_select.py
+++ b/lib/sqlalchemy/testing/suite/test_select.py
@@ -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:
diff --git a/lib/sqlalchemy/testing/suite/test_update_delete.py b/lib/sqlalchemy/testing/suite/test_update_delete.py
index 6003a0994..f7e6da98e 100644
--- a/lib/sqlalchemy/testing/suite/test_update_delete.py
+++ b/lib/sqlalchemy/testing/suite/test_update_delete.py
@@ -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
diff --git a/test/aaa_profiling/test_orm.py b/test/aaa_profiling/test_orm.py
index cecb0f240..6560681ba 100644
--- a/test/aaa_profiling/test_orm.py
+++ b/test/aaa_profiling/test_orm.py
@@ -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()
diff --git a/test/dialect/mysql/test_for_update.py b/test/dialect/mysql/test_for_update.py
index 1e8df858f..5897a094d 100644
--- a/test/dialect/mysql/test_for_update.py
+++ b/test/dialect/mysql/test_for_update.py
@@ -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)]),
diff --git a/test/dialect/mysql/test_query.py b/test/dialect/mysql/test_query.py
index 0c1e623fe..a7ed45b3b 100644
--- a/test/dialect/mysql/test_query.py
+++ b/test/dialect/mysql/test_query.py
@@ -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
diff --git a/test/dialect/oracle/test_types.py b/test/dialect/oracle/test_types.py
index e0d97230c..ffcac6591 100644
--- a/test/dialect/oracle/test_types.py
+++ b/test/dialect/oracle/test_types.py
@@ -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))
diff --git a/test/dialect/postgresql/test_query.py b/test/dialect/postgresql/test_query.py
index 74ad19d1a..7f311778e 100644
--- a/test/dialect/postgresql/test_query.py
+++ b/test/dialect/postgresql/test_query.py
@@ -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),
diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py
index 1903e47d4..34ea4d7ed 100644
--- a/test/dialect/postgresql/test_types.py
+++ b/test/dialect/postgresql/test_types.py
@@ -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
diff --git a/test/ext/declarative/test_basic.py b/test/ext/declarative/test_basic.py
index cb70b59f1..7dfcc70bb 100644
--- a/test/ext/declarative/test_basic.py
+++ b/test/ext/declarative/test_basic.py
@@ -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):
diff --git a/test/ext/test_associationproxy.py b/test/ext/test_associationproxy.py
index ddca2f78e..6fdcf3e11 100644
--- a/test/ext/test_associationproxy.py
+++ b/test/ext/test_associationproxy.py
@@ -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")]),
diff --git a/test/ext/test_horizontal_shard.py b/test/ext/test_horizontal_shard.py
index 70a126f4f..7665711a9 100644
--- a/test/ext/test_horizontal_shard.py
+++ b/test/ext/test_horizontal_shard.py
@@ -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()
diff --git a/test/ext/test_hybrid.py b/test/ext/test_hybrid.py
index ab57ce6f4..353c52c5c 100644
--- a/test/ext/test_hybrid.py
+++ b/test/ext/test_hybrid.py
@@ -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()
diff --git a/test/ext/test_serializer.py b/test/ext/test_serializer.py
index ac5133fda..4080a0044 100644
--- a/test/ext/test_serializer.py
+++ b/test/ext/test_serializer.py
@@ -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):
diff --git a/test/orm/inheritance/_poly_fixtures.py b/test/orm/inheritance/_poly_fixtures.py
index 2a3a5dcff..c9cde7a81 100644
--- a/test/orm/inheritance/_poly_fixtures.py
+++ b/test/orm/inheritance/_poly_fixtures.py
@@ -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()
diff --git a/test/orm/inheritance/test_assorted_poly.py b/test/orm/inheritance/test_assorted_poly.py
index 616ed79a6..029573c5f 100644
--- a/test/orm/inheritance/test_assorted_poly.py
+++ b/test/orm/inheritance/test_assorted_poly.py
@@ -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")
diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py
index 9b896b59a..cb4e70ecb 100644
--- a/test/orm/inheritance/test_basic.py
+++ b/test/orm/inheritance/test_basic.py
@@ -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"
)
diff --git a/test/orm/inheritance/test_concrete.py b/test/orm/inheritance/test_concrete.py
index cea7eeaac..376337b25 100644
--- a/test/orm/inheritance/test_concrete.py
+++ b/test/orm/inheritance/test_concrete.py
@@ -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"),
)
diff --git a/test/orm/inheritance/test_poly_loading.py b/test/orm/inheritance/test_poly_loading.py
index c40794ef4..416a52f62 100644
--- a/test/orm/inheritance/test_poly_loading.py
+++ b/test/orm/inheritance/test_poly_loading.py
@@ -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)
diff --git a/test/orm/inheritance/test_poly_persistence.py b/test/orm/inheritance/test_poly_persistence.py
index deb33838f..25eeb3d1d 100644
--- a/test/orm/inheritance/test_poly_persistence.py
+++ b/test/orm/inheritance/test_poly_persistence.py
@@ -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)
diff --git a/test/orm/inheritance/test_polymorphic_rel.py b/test/orm/inheritance/test_polymorphic_rel.py
index 830d60b95..8be25f2b9 100644
--- a/test/orm/inheritance/test_polymorphic_rel.py
+++ b/test/orm/inheritance/test_polymorphic_rel.py
@@ -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
diff --git a/test/orm/inheritance/test_relationship.py b/test/orm/inheritance/test_relationship.py
index b7d49829e..a4dde3f02 100644
--- a/test/orm/inheritance/test_relationship.py
+++ b/test/orm/inheritance/test_relationship.py
@@ -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()
diff --git a/test/orm/inheritance/test_single.py b/test/orm/inheritance/test_single.py
index 553380ac7..b32a8af3d 100644
--- a/test/orm/inheritance/test_single.py
+++ b/test/orm/inheritance/test_single.py
@@ -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(
diff --git a/test/orm/test_ac_relationships.py b/test/orm/test_ac_relationships.py
index bb99636d4..ce2dbddf7 100644
--- a/test/orm/test_ac_relationships.py
+++ b/test/orm/test_ac_relationships.py
@@ -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),
diff --git a/test/orm/test_assorted_eager.py b/test/orm/test_assorted_eager.py
index 5c62165f9..df3917712 100644
--- a/test/orm/test_assorted_eager.py
+++ b/test/orm/test_assorted_eager.py
@@ -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")
diff --git a/test/orm/test_bundle.py b/test/orm/test_bundle.py
index a17a00ed0..f6d4e8e37 100644
--- a/test/orm/test_bundle.py
+++ b/test/orm/test_bundle.py
@@ -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(
diff --git a/test/orm/test_cascade.py b/test/orm/test_cascade.py
index 815df3620..7b54f3bc1 100644
--- a/test/orm/test_cascade.py
+++ b/test/orm/test_cascade.py
@@ -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()
diff --git a/test/orm/test_deferred.py b/test/orm/test_deferred.py
index a02ee250c..b9198033b 100644
--- a/test/orm/test_deferred.py
+++ b/test/orm/test_deferred.py
@@ -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()
diff --git a/test/orm/test_eager_relations.py b/test/orm/test_eager_relations.py
index ecc371117..3a6810d80 100644
--- a/test/orm/test_eager_relations.py
+++ b/test/orm/test_eager_relations.py
@@ -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()
diff --git a/test/orm/test_events.py b/test/orm/test_events.py
index c25970e2c..225468baa 100644
--- a/test/orm/test_events.py
+++ b/test/orm/test_events.py
@@ -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()
diff --git a/test/orm/test_expire.py b/test/orm/test_expire.py
index 127380fad..f38f917da 100644
--- a/test/orm/test_expire.py
+++ b/test/orm/test_expire.py
@@ -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"},
)
diff --git a/test/orm/test_froms.py b/test/orm/test_froms.py
index 5ac4a15ec..08b59ce67 100644
--- a/test/orm/test_froms.py
+++ b/test/orm/test_froms.py
@@ -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()
diff --git a/test/orm/test_joins.py b/test/orm/test_joins.py
index 2cd30d88d..1895a41e8 100644
--- a/test/orm/test_joins.py
+++ b/test/orm/test_joins.py
@@ -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")
diff --git a/test/orm/test_lazy_relations.py b/test/orm/test_lazy_relations.py
index 1c2720898..be8301bae 100644
--- a/test/orm/test_lazy_relations.py
+++ b/test/orm/test_lazy_relations.py
@@ -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)},
diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py
index e4ba50f13..545bf8e01 100644
--- a/test/orm/test_mapper.py
+++ b/test/orm/test_mapper.py
@@ -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):
diff --git a/test/orm/test_merge.py b/test/orm/test_merge.py
index b5e1ee415..6b03717d3 100644
--- a/test/orm/test_merge.py
+++ b/test/orm/test_merge.py
@@ -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(
diff --git a/test/orm/test_of_type.py b/test/orm/test_of_type.py
index 9e9387db9..82930f754 100644
--- a/test/orm/test_of_type.py
+++ b/test/orm/test_of_type.py
@@ -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()
diff --git a/test/orm/test_relationships.py b/test/orm/test_relationships.py
index c9a314212..f958bc1cf 100644
--- a/test/orm/test_relationships.py
+++ b/test/orm/test_relationships.py
@@ -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"),
diff --git a/test/orm/test_selectin_relations.py b/test/orm/test_selectin_relations.py
index 5039ab0a8..d89fb4949 100644
--- a/test/orm/test_selectin_relations.py
+++ b/test/orm/test_selectin_relations.py
@@ -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):
diff --git a/test/orm/test_subquery_relations.py b/test/orm/test_subquery_relations.py
index f3fdfd3dc..c2afe6f99 100644
--- a/test/orm/test_subquery_relations.py
+++ b/test/orm/test_subquery_relations.py
@@ -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()
diff --git a/test/orm/test_update_delete.py b/test/orm/test_update_delete.py
index 4384fa67e..bec4ecd92 100644
--- a/test/orm/test_update_delete.py
+++ b/test/orm/test_update_delete.py
@@ -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"),
diff --git a/test/sql/test_defaults.py b/test/sql/test_defaults.py
index 0a50a6356..fd5aec503 100644
--- a/test/sql/test_defaults.py
+++ b/test/sql/test_defaults.py
@@ -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):
diff --git a/test/sql/test_deprecations.py b/test/sql/test_deprecations.py
index 13d4cd154..43e906032 100644
--- a/test/sql/test_deprecations.py
+++ b/test/sql/test_deprecations.py
@@ -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
diff --git a/test/sql/test_resultset.py b/test/sql/test_resultset.py
index f8d245228..470417dd3 100644
--- a/test/sql/test_resultset.py
+++ b/test/sql/test_resultset.py
@@ -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):