summaryrefslogtreecommitdiff
path: root/test/orm/inheritance
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-01-04 15:18:25 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2021-01-05 23:46:02 -0500
commit6fccdf4a285d5332ef49f23dc18c3ce45501d78b (patch)
treed276e13e8960f00dc088c40908e4991248cc8639 /test/orm/inheritance
parent640cd8a70f8a664b7834c5f74ec322fdea644043 (diff)
downloadsqlalchemy-6fccdf4a285d5332ef49f23dc18c3ce45501d78b.tar.gz
remove more bound metadata
in Iae6ab95938a7e92b6d42086aec534af27b5577d3 I missed that the "bind" was being stuck onto the MetaData in TablesTest, which led thousands of ORM tests to still use bound metadata. Keep looking for bound metadata. standardize all ORM tests on a single means of getting a Session when the Session API isn't the thing we are directly testing, using a new function fixture_session() that replaces create_session() and uses modern defaults. Change-Id: Iaf71206e9ee568151496d8bc213a069504bf65ef
Diffstat (limited to 'test/orm/inheritance')
-rw-r--r--test/orm/inheritance/test_abc_inheritance.py4
-rw-r--r--test/orm/inheritance/test_abc_polymorphic.py4
-rw-r--r--test/orm/inheritance/test_assorted_poly.py49
-rw-r--r--test/orm/inheritance/test_basic.py127
-rw-r--r--test/orm/inheritance/test_concrete.py27
-rw-r--r--test/orm/inheritance/test_magazine.py4
-rw-r--r--test/orm/inheritance/test_manytomany.py12
-rw-r--r--test/orm/inheritance/test_poly_linked_list.py4
-rw-r--r--test/orm/inheritance/test_poly_loading.py19
-rw-r--r--test/orm/inheritance/test_poly_persistence.py22
-rw-r--r--test/orm/inheritance/test_polymorphic_rel.py300
-rw-r--r--test/orm/inheritance/test_productspec.py12
-rw-r--r--test/orm/inheritance/test_relationship.py100
-rw-r--r--test/orm/inheritance/test_selects.py3
-rw-r--r--test/orm/inheritance/test_single.py79
-rw-r--r--test/orm/inheritance/test_with_poly.py12
16 files changed, 388 insertions, 390 deletions
diff --git a/test/orm/inheritance/test_abc_inheritance.py b/test/orm/inheritance/test_abc_inheritance.py
index bce554f30..a368e7b2f 100644
--- a/test/orm/inheritance/test_abc_inheritance.py
+++ b/test/orm/inheritance/test_abc_inheritance.py
@@ -9,7 +9,7 @@ from sqlalchemy.orm import relationship
from sqlalchemy.orm.interfaces import MANYTOONE
from sqlalchemy.orm.interfaces import ONETOMANY
from sqlalchemy.testing import fixtures
-from sqlalchemy.testing.fixtures import create_session
+from sqlalchemy.testing.fixtures import fixture_session
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
@@ -221,7 +221,7 @@ class ABCTest(fixtures.MappedTest):
parent_class = {"a": A, "b": B, "c": C}[parent]
child_class = {"a": A, "b": B, "c": C}[child]
- sess = create_session()
+ sess = fixture_session(autoflush=False, expire_on_commit=False)
parent_obj = parent_class("parent1")
child_obj = child_class("child1")
diff --git a/test/orm/inheritance/test_abc_polymorphic.py b/test/orm/inheritance/test_abc_polymorphic.py
index 0d28ef342..fd3d50ddd 100644
--- a/test/orm/inheritance/test_abc_polymorphic.py
+++ b/test/orm/inheritance/test_abc_polymorphic.py
@@ -5,7 +5,7 @@ from sqlalchemy import testing
from sqlalchemy.orm import mapper
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
-from sqlalchemy.testing.fixtures import create_session
+from sqlalchemy.testing.fixtures import fixture_session
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
@@ -77,7 +77,7 @@ class ABCTest(fixtures.MappedTest):
c2 = C(cdata="c2", bdata="c2", adata="c2")
c3 = C(cdata="c2", bdata="c2", adata="c2")
- sess = create_session()
+ sess = fixture_session()
for x in (a1, b1, b2, b3, c1, c2, c3):
sess.add(x)
sess.flush()
diff --git a/test/orm/inheritance/test_assorted_poly.py b/test/orm/inheritance/test_assorted_poly.py
index ce8d76a53..3cf9c9837 100644
--- a/test/orm/inheritance/test_assorted_poly.py
+++ b/test/orm/inheritance/test_assorted_poly.py
@@ -21,14 +21,13 @@ from sqlalchemy.orm import joinedload
from sqlalchemy.orm import mapper
from sqlalchemy.orm import polymorphic_union
from sqlalchemy.orm import relationship
-from sqlalchemy.orm import Session
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import with_polymorphic
from sqlalchemy.orm.interfaces import MANYTOONE
from sqlalchemy.testing import AssertsExecutionResults
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
-from sqlalchemy.testing.fixtures import create_session
+from sqlalchemy.testing.fixtures import fixture_session
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
@@ -108,7 +107,7 @@ class RelationshipTest1(fixtures.MappedTest):
[(managers.c.person_id, people.c.manager_id)],
)
- session = create_session()
+ session = fixture_session()
p = Person(name="some person")
m = Manager(name="some manager")
p.manager = m
@@ -140,7 +139,7 @@ class RelationshipTest1(fixtures.MappedTest):
},
)
- session = create_session()
+ session = fixture_session()
p = Person(name="some person")
m = Manager(name="some manager")
m.employee = p
@@ -297,7 +296,7 @@ class RelationshipTest2(fixtures.MappedTest):
},
)
- sess = create_session()
+ sess = fixture_session()
p = Person(name="person1")
m = Manager(name="manager1")
m.colleague = p
@@ -462,7 +461,7 @@ class RelationshipTest3(fixtures.MappedTest):
self._setup_mappings(jointype, usedata)
Person, Manager, Data = self.classes("Person", "Manager", "Data")
- sess = create_session()
+ sess = fixture_session()
p = Person(name="person1")
p2 = Person(name="person2")
p3 = Person(name="person3")
@@ -611,7 +610,7 @@ class RelationshipTest4(fixtures.MappedTest):
)
mapper(Car, cars, properties={"employee": relationship(person_mapper)})
- session = create_session()
+ session = fixture_session()
# creating 5 managers named from M1 to E5
for i in range(1, 5):
@@ -780,7 +779,7 @@ class RelationshipTest5(fixtures.MappedTest):
},
)
- sess = create_session()
+ sess = fixture_session()
car1 = Car()
car2 = Car()
car2.manager = Manager()
@@ -855,7 +854,7 @@ class RelationshipTest6(fixtures.MappedTest):
},
)
- sess = create_session()
+ sess = fixture_session()
m = Manager(name="manager1")
m2 = Manager(name="manager2")
m.colleague = m2
@@ -1027,7 +1026,7 @@ class RelationshipTest7(fixtures.MappedTest):
polymorphic_identity="manager",
)
- session = create_session()
+ session = fixture_session()
for i in range(1, 4):
if i % 2:
@@ -1095,7 +1094,7 @@ class RelationshipTest8(fixtures.MappedTest):
u1 = User(data="u1")
t1 = Taggable(owner=u1)
- sess = create_session()
+ sess = fixture_session()
sess.add(t1)
sess.flush()
@@ -1303,7 +1302,7 @@ class GenerativeTest(fixtures.MappedTest, AssertsExecutionResults):
Status, Person, Engineer, Manager, Car = self.classes(
"Status", "Person", "Engineer", "Manager", "Car"
)
- session = create_session()
+ session = fixture_session()
r = (
session.query(Person)
@@ -1328,7 +1327,7 @@ class GenerativeTest(fixtures.MappedTest, AssertsExecutionResults):
Status, Person, Engineer, Manager, Car = self.classes(
"Status", "Person", "Engineer", "Manager", "Car"
)
- session = create_session()
+ session = fixture_session()
r = (
session.query(Engineer)
.join("status")
@@ -1351,7 +1350,7 @@ class GenerativeTest(fixtures.MappedTest, AssertsExecutionResults):
Status, Person, Engineer, Manager, Car = self.classes(
"Status", "Person", "Engineer", "Manager", "Car"
)
- session = create_session()
+ session = fixture_session()
r = session.query(Person).filter(
exists().where(Car.owner == Person.person_id)
)
@@ -1471,7 +1470,7 @@ class MultiLevelTest(fixtures.MappedTest):
b = Engineer().set(egn="two", machine="any")
c = Manager().set(name="head", machine="fast", duties="many")
- session = create_session()
+ session = fixture_session()
session.add(a)
session.add(b)
session.add(c)
@@ -1621,7 +1620,7 @@ class CustomPKTest(fixtures.MappedTest):
mapper(T2, t2, inherits=T1, polymorphic_identity="t2")
ot1 = T1()
ot2 = T2()
- sess = create_session()
+ sess = fixture_session()
sess.add(ot1)
sess.add(ot2)
sess.flush()
@@ -1668,7 +1667,7 @@ class CustomPKTest(fixtures.MappedTest):
ot1 = T1()
ot2 = T2()
- sess = create_session()
+ sess = fixture_session()
sess.add(ot1)
sess.add(ot2)
sess.flush()
@@ -1754,7 +1753,7 @@ class InheritingEagerTest(fixtures.MappedTest):
)
mapper(Tag, tags)
- session = create_session()
+ session = fixture_session()
bob = Employee()
session.add(bob)
@@ -1852,7 +1851,7 @@ class MissingPolymorphicOnTest(fixtures.MappedTest):
c = C(cdata="c1", adata="a1", b=B(data="c"))
d = D(cdata="c2", adata="a2", ddata="d2", b=B(data="d"))
- sess = create_session()
+ sess = fixture_session()
sess.add(c)
sess.add(d)
sess.flush()
@@ -1899,7 +1898,7 @@ class JoinedInhAdjacencyTest(fixtures.MappedTest):
def _roundtrip(self):
User = self.classes.User
- sess = Session()
+ sess = fixture_session()
u1 = User()
u2 = User()
u2.supervisor = u1
@@ -1910,7 +1909,7 @@ class JoinedInhAdjacencyTest(fixtures.MappedTest):
def _dude_roundtrip(self):
Dude, User = self.classes.Dude, self.classes.User
- sess = Session()
+ sess = fixture_session()
u1 = User()
d1 = Dude()
d1.supervisor = u1
@@ -2070,7 +2069,7 @@ class Ticket2419Test(fixtures.DeclarativeMappedTest):
)
def test_join_w_eager_w_any(self):
B, C, D = (self.classes.B, self.classes.C, self.classes.D)
- s = Session(testing.db)
+ s = fixture_session()
b = B(ds=[D()])
s.add_all([C(b=b)])
@@ -2114,7 +2113,7 @@ class ColSubclassTest(
def test_polymorphic_adaptation(self):
A, B = self.classes.A, self.classes.B
- s = Session()
+ s = fixture_session()
self.assert_compile(
s.query(A).join(B).filter(B.x == "test"),
"SELECT a.id AS a_id FROM a JOIN "
@@ -2181,7 +2180,7 @@ class CorrelateExceptWPolyAdaptTest(
poly = with_polymorphic(Superclass, "*")
- s = Session()
+ s = fixture_session()
q = (
s.query(poly)
.options(contains_eager(poly.common_relationship))
@@ -2210,7 +2209,7 @@ class CorrelateExceptWPolyAdaptTest(
poly = with_polymorphic(Superclass, "*")
- s = Session()
+ s = fixture_session()
q = (
s.query(poly)
.options(contains_eager(poly.common_relationship))
diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py
index af960625e..bdcdedc44 100644
--- a/test/orm/inheritance/test_basic.py
+++ b/test/orm/inheritance/test_basic.py
@@ -27,7 +27,6 @@ from sqlalchemy.orm import object_mapper
from sqlalchemy.orm import polymorphic_union
from sqlalchemy.orm import relationship
from sqlalchemy.orm import Session
-from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import synonym
from sqlalchemy.orm.util import instance_str
from sqlalchemy.testing import assert_raises
@@ -42,7 +41,7 @@ from sqlalchemy.testing.assertsql import CompiledSQL
from sqlalchemy.testing.assertsql import Conditional
from sqlalchemy.testing.assertsql import Or
from sqlalchemy.testing.assertsql import RegexSQL
-from sqlalchemy.testing.fixtures import create_session
+from sqlalchemy.testing.fixtures import fixture_session
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
@@ -104,7 +103,7 @@ class O2MTest(fixtures.MappedTest):
properties={"parent_foo": relationship(Foo)},
)
- sess = create_session()
+ sess = fixture_session()
b1 = Blub("blub #1")
b2 = Blub("blub #2")
f = Foo("foo #1")
@@ -166,7 +165,7 @@ class ColExpressionsTest(fixtures.DeclarativeMappedTest):
def test_group_by(self):
B = self.classes.B
- s = Session()
+ s = fixture_session()
rows = (
s.query(B.id.expressions[0], B.id.expressions[1], func.sum(B.data))
@@ -222,7 +221,7 @@ class PolyExpressionEagerLoad(fixtures.DeclarativeMappedTest):
A = self.classes.A
B = self.classes.B
- session = Session(testing.db)
+ session = fixture_session()
result = (
session.query(A)
.filter_by(child_id=None)
@@ -590,7 +589,7 @@ class PolymorphicOnNotLocalTest(fixtures.MappedTest):
else:
assert False, "Got unexpected identity %r" % ident
- s = Session(testing.db)
+ s = fixture_session()
s.add_all([Parent(q="p1"), Child(q="c1", y="c1"), Parent(q="p2")])
s.commit()
s.close()
@@ -647,7 +646,7 @@ class SortOnlyOnImportantFKsTest(fixtures.MappedTest):
cls.classes.B = B
def test_flush(self):
- s = Session(testing.db)
+ s = fixture_session()
s.add(self.classes.B())
s.flush()
@@ -674,7 +673,7 @@ class FalseDiscriminatorTest(fixtures.MappedTest):
mapper(Foo, t1, polymorphic_on=t1.c.type, polymorphic_identity=True)
mapper(Bar, inherits=Foo, polymorphic_identity=False)
- sess = create_session()
+ sess = fixture_session()
b1 = Bar()
sess.add(b1)
sess.flush()
@@ -691,7 +690,7 @@ class FalseDiscriminatorTest(fixtures.MappedTest):
mapper(Ding, t1, polymorphic_on=t1.c.type, polymorphic_identity=False)
mapper(Bat, inherits=Ding, polymorphic_identity=True)
- sess = create_session()
+ sess = fixture_session()
d1 = Ding()
sess.add(d1)
sess.flush()
@@ -741,7 +740,7 @@ class PolymorphicSynonymTest(fixtures.MappedTest):
properties={"info": synonym("_info", map_column=True)},
)
mapper(T2, t2, inherits=T1, polymorphic_identity="t2")
- sess = create_session()
+ sess = fixture_session()
at1 = T1(info="at1")
at2 = T2(info="at2", data="t2 data")
sess.add(at1)
@@ -832,7 +831,7 @@ class PolymorphicAttributeManagementTest(fixtures.MappedTest):
def test_base_class(self):
A, C, B = (self.classes.A, self.classes.C, self.classes.B)
- sess = Session()
+ sess = fixture_session()
c1 = C()
sess.add(c1)
sess.commit()
@@ -849,7 +848,7 @@ class PolymorphicAttributeManagementTest(fixtures.MappedTest):
"""
D, B = self.classes.D, self.classes.B
- sess = Session()
+ sess = fixture_session()
b1 = B()
b1.class_name = "d"
sess.add(b1)
@@ -863,7 +862,7 @@ class PolymorphicAttributeManagementTest(fixtures.MappedTest):
"""
C = self.classes.C
- sess = Session()
+ sess = fixture_session()
c1 = C()
c1.class_name = "b"
sess.add(c1)
@@ -882,7 +881,7 @@ class PolymorphicAttributeManagementTest(fixtures.MappedTest):
"""
B = self.classes.B
- sess = Session()
+ sess = fixture_session()
b1 = B()
b1.class_name = "c"
sess.add(b1)
@@ -898,7 +897,7 @@ class PolymorphicAttributeManagementTest(fixtures.MappedTest):
"""test warn on an unknown polymorphic identity."""
B = self.classes.B
- sess = Session()
+ sess = fixture_session()
b1 = B()
b1.class_name = "xyz"
sess.add(b1)
@@ -913,7 +912,7 @@ class PolymorphicAttributeManagementTest(fixtures.MappedTest):
def test_not_set_on_upate(self):
C = self.classes.C
- sess = Session()
+ sess = fixture_session()
c1 = C()
sess.add(c1)
sess.commit()
@@ -925,7 +924,7 @@ class PolymorphicAttributeManagementTest(fixtures.MappedTest):
def test_validate_on_upate(self):
C = self.classes.C
- sess = Session()
+ sess = fixture_session()
c1 = C()
sess.add(c1)
sess.commit()
@@ -1009,7 +1008,7 @@ class CascadeTest(fixtures.MappedTest):
)
mapper(T4, t4)
- sess = create_session()
+ sess = fixture_session()
t1_1 = T1(data="t1")
t3_1 = T3(data="t3", moredata="t3")
@@ -1095,7 +1094,7 @@ class M2OUseGetTest(fixtures.MappedTest):
assert class_mapper(Related).get_property("sub").strategy.use_get
- sess = create_session()
+ sess = fixture_session()
s1 = Sub()
r1 = Related(sub=s1)
sess.add(r1)
@@ -1181,7 +1180,7 @@ class GetTest(fixtures.MappedTest):
mapper(Bar, bar, inherits=Foo)
mapper(Blub, blub, inherits=Bar)
- sess = create_session()
+ sess = fixture_session()
f = Foo()
b = Bar()
bl = Blub()
@@ -1295,7 +1294,7 @@ class EagerLazyTest(fixtures.MappedTest):
def test_basic(self):
Bar = self.classes.Bar
- sess = create_session()
+ sess = fixture_session()
q = sess.query(Bar)
self.assert_(len(q.first().lazy) == 1)
self.assert_(len(q.first().eager) == 1)
@@ -1350,7 +1349,7 @@ class EagerTargetingTest(fixtures.MappedTest):
},
)
- sess = create_session()
+ sess = fixture_session()
b1 = B(id=1, name="b1", b_data="i")
sess.add(b1)
@@ -1454,7 +1453,7 @@ class FlushTest(fixtures.MappedTest):
},
)
mapper(Admin, admins, inherits=user_mapper)
- sess = create_session()
+ sess = fixture_session()
adminrole = Role()
sess.add(adminrole)
sess.flush()
@@ -1507,7 +1506,7 @@ class FlushTest(fixtures.MappedTest):
# create roles
adminrole = Role("admin")
- sess = create_session()
+ sess = fixture_session()
sess.add(adminrole)
sess.flush()
@@ -1581,7 +1580,7 @@ class PassiveDeletesTest(fixtures.MappedTest):
A, B, C = self.classes("A", "B", "C")
self._fixture()
- s = Session()
+ s = fixture_session()
a1, b1, c1 = A(id=1), B(id=2), C(cid=1, id=3)
s.add_all([a1, b1, c1])
s.commit()
@@ -1605,7 +1604,7 @@ class PassiveDeletesTest(fixtures.MappedTest):
A, B, C = self.classes("A", "B", "C")
self._fixture(c_p=True)
- s = Session()
+ s = fixture_session()
a1, b1, c1 = A(id=1), B(id=2), C(cid=1, id=3)
s.add_all([a1, b1, c1])
s.commit()
@@ -1647,7 +1646,7 @@ class PassiveDeletesTest(fixtures.MappedTest):
A, B, C = self.classes("A", "B", "C")
self._fixture(b_p=True)
- s = Session()
+ s = fixture_session()
a1, b1, c1 = A(id=1), B(id=2), C(cid=1, id=3)
s.add_all([a1, b1, c1])
s.commit()
@@ -1685,7 +1684,7 @@ class PassiveDeletesTest(fixtures.MappedTest):
A, B, C = self.classes("A", "B", "C")
self._fixture(a_p=True)
- s = Session()
+ s = fixture_session()
a1, b1, c1 = A(id=1), B(id=2), C(cid=1, id=3)
s.add_all([a1, b1, c1])
s.commit()
@@ -1767,7 +1766,7 @@ class OptimizedGetOnDeferredTest(fixtures.MappedTest):
def test_column_property(self):
A, B = self.classes("A", "B")
- sess = Session()
+ sess = fixture_session()
b1 = B(data="x")
sess.add(b1)
sess.flush()
@@ -1776,7 +1775,7 @@ class OptimizedGetOnDeferredTest(fixtures.MappedTest):
def test_expired_column(self):
A, B = self.classes("A", "B")
- sess = Session()
+ sess = fixture_session()
b1 = B(data="x")
sess.add(b1)
sess.flush()
@@ -1830,7 +1829,7 @@ class JoinedNoFKSortingTest(fixtures.MappedTest):
def test_ordering(self):
B, C = self.classes.B, self.classes.C
- sess = Session()
+ sess = fixture_session()
sess.add_all([B(), C(), B(), C()])
self.assert_sql_execution(
testing.db,
@@ -1918,7 +1917,7 @@ class VersioningTest(fixtures.MappedTest):
)
mapper(Sub, subtable, inherits=Base, polymorphic_identity=2)
- sess = Session(autoflush=False)
+ sess = fixture_session(autoflush=False)
b1 = Base(value="b1")
s1 = Sub(value="sub1", subdata="some subdata")
@@ -1927,7 +1926,7 @@ class VersioningTest(fixtures.MappedTest):
sess.commit()
- sess2 = Session(autoflush=False)
+ sess2 = fixture_session(autoflush=False)
s2 = sess2.get(Base, s1.id)
s2.subdata = "sess2 subdata"
@@ -1976,7 +1975,7 @@ class VersioningTest(fixtures.MappedTest):
)
mapper(Sub, subtable, inherits=Base, polymorphic_identity=2)
- sess = Session(autoflush=False, expire_on_commit=False)
+ sess = fixture_session(autoflush=False, expire_on_commit=False)
b1 = Base(value="b1")
s1 = Sub(value="sub1", subdata="some subdata")
@@ -1987,7 +1986,7 @@ class VersioningTest(fixtures.MappedTest):
sess.commit()
- sess2 = Session(autoflush=False, expire_on_commit=False)
+ sess2 = fixture_session(autoflush=False, expire_on_commit=False)
s3 = sess2.get(Base, s1.id)
sess2.delete(s3)
sess2.commit()
@@ -2099,7 +2098,7 @@ class DistinctPKTest(fixtures.MappedTest):
self._do_test(False)
def _do_test(self, composite):
- session = create_session()
+ session = fixture_session()
if composite:
alice1 = session.get(Employee, [1, 2])
@@ -2178,7 +2177,7 @@ class SyncCompileTest(fixtures.MappedTest):
mapper(B, _b_table, inherits=A, inherit_condition=j1)
mapper(C, _c_table, inherits=B, inherit_condition=j2)
- session = create_session()
+ session = fixture_session()
a = A(data1="a1")
session.add(a)
@@ -2284,7 +2283,7 @@ class OverrideColKeyTest(fixtures.MappedTest):
s1 = Sub()
s1.id = 10
- sess = create_session()
+ sess = fixture_session()
sess.add(s1)
sess.flush()
assert sess.get(Sub, 10) is s1
@@ -2312,7 +2311,7 @@ class OverrideColKeyTest(fixtures.MappedTest):
s2 = Sub()
s2.base_id = 15
- sess = create_session()
+ sess = fixture_session()
sess.add_all([s1, s2])
sess.flush()
@@ -2384,7 +2383,7 @@ class OverrideColKeyTest(fixtures.MappedTest):
mapper(Sub, subtable, inherits=Base)
s1 = Sub()
- sess = create_session()
+ sess = fixture_session()
sess.add(s1)
sess.flush()
assert sess.query(Sub).one().data == "im the data"
@@ -2409,7 +2408,7 @@ class OverrideColKeyTest(fixtures.MappedTest):
mapper(Sub, subtable, inherits=Base)
s1 = Sub()
- sess = create_session()
+ sess = fixture_session()
sess.add(s1)
sess.flush()
assert sess.query(Sub).one().data == "im the data"
@@ -2426,7 +2425,7 @@ class OverrideColKeyTest(fixtures.MappedTest):
mapper(Base, base)
mapper(Sub, subtable, inherits=Base)
- sess = create_session()
+ sess = fixture_session()
b1 = Base()
assert b1.subdata == "this is base"
s1 = Sub()
@@ -2452,7 +2451,7 @@ class OverrideColKeyTest(fixtures.MappedTest):
mapper(Base, base)
mapper(Sub, subtable, inherits=Base)
- sess = create_session()
+ sess = fixture_session()
b1 = Base()
assert b1.data == "this is base"
s1 = Sub()
@@ -2528,7 +2527,7 @@ class OptimizedLoadTest(fixtures.MappedTest):
)
mapper(SubJoinBase, inherits=JoinBase)
- sess = Session()
+ sess = fixture_session()
sess.add(Base(data="data"))
sess.commit()
@@ -2595,7 +2594,7 @@ class OptimizedLoadTest(fixtures.MappedTest):
base.outerjoin(sub).select().apply_labels().alias("foo"),
),
)
- sess = Session()
+ sess = fixture_session()
s1 = Sub(
data="s1data", sub="s1sub", subcounter=1, counter=1, subcounter2=1
)
@@ -2638,7 +2637,7 @@ class OptimizedLoadTest(fixtures.MappedTest):
polymorphic_identity="sub",
properties={"id": [sub.c.id, base.c.id]},
)
- sess = sessionmaker()()
+ sess = fixture_session()
s1 = Sub(data="s1data", sub="s1sub")
sess.add(s1)
sess.commit()
@@ -2673,7 +2672,7 @@ class OptimizedLoadTest(fixtures.MappedTest):
"concat": column_property(sub.c.sub + "|" + sub.c.sub)
},
)
- sess = sessionmaker()()
+ sess = fixture_session()
s1 = Sub(data="s1data", sub="s1sub")
sess.add(s1)
sess.commit()
@@ -2702,7 +2701,7 @@ class OptimizedLoadTest(fixtures.MappedTest):
"concat": column_property(base.c.data + "|" + sub.c.sub)
},
)
- sess = sessionmaker()()
+ sess = fixture_session()
s1 = Sub(data="s1data", sub="s1sub")
s2 = Sub(data="s2data", sub="s2sub")
s3 = Sub(data="s3data", sub="s3sub")
@@ -2752,7 +2751,7 @@ class OptimizedLoadTest(fixtures.MappedTest):
polymorphic_identity="wc",
properties={"comp": composite(Comp, with_comp.c.a, with_comp.c.b)},
)
- sess = sessionmaker()()
+ sess = fixture_session()
s1 = WithComp(data="s1data", comp=Comp("ham", "cheese"))
s2 = WithComp(data="s2data", comp=Comp("bacon", "eggs"))
sess.add_all([s1, s2])
@@ -2777,7 +2776,7 @@ class OptimizedLoadTest(fixtures.MappedTest):
Base, base, polymorphic_on=base.c.type, polymorphic_identity="base"
)
mapper(Sub, sub, inherits=Base, polymorphic_identity="sub")
- sess = Session()
+ sess = fixture_session()
s1 = Sub(data="s1")
sess.add(s1)
self.assert_sql_execution(
@@ -2871,7 +2870,7 @@ class OptimizedLoadTest(fixtures.MappedTest):
)
mapper(Sub, sub, inherits=Base, polymorphic_identity="sub")
mapper(SubSub, subsub, inherits=Sub, polymorphic_identity="subsub")
- sess = Session()
+ sess = fixture_session()
s1 = SubSub(data="s1", counter=1, subcounter=2)
sess.add(s1)
self.assert_sql_execution(
@@ -3152,7 +3151,7 @@ class PKDiscriminatorTest(fixtures.MappedTest):
mapper(A, inherits=Child, polymorphic_identity=2)
- s = create_session()
+ s = fixture_session()
p = Parent("p1")
a = A("a1")
p.children.append(a)
@@ -3220,7 +3219,7 @@ class NoPolyIdentInMiddleTest(fixtures.MappedTest):
def test_load_from_middle(self):
C, B = self.classes.C, self.classes.B
- s = Session()
+ s = fixture_session()
s.add(C())
o = s.query(B).first()
eq_(o.type, "c")
@@ -3229,7 +3228,7 @@ class NoPolyIdentInMiddleTest(fixtures.MappedTest):
def test_load_from_base(self):
A, C = self.classes.A, self.classes.C
- s = Session()
+ s = fixture_session()
s.add(C())
o = s.query(A).first()
eq_(o.type, "c")
@@ -3250,7 +3249,7 @@ class NoPolyIdentInMiddleTest(fixtures.MappedTest):
self.tables.base,
)
- s = Session()
+ s = fixture_session()
s.add_all([C(), D(), E()])
eq_(s.query(B).order_by(base.c.type).all(), [C(), D()])
@@ -3314,7 +3313,7 @@ class DeleteOrphanTest(fixtures.MappedTest):
},
)
- sess = create_session()
+ sess = fixture_session()
s1 = SubClass(data="s1")
sess.add(s1)
assert_raises(sa_exc.DBAPIError, sess.flush)
@@ -3418,7 +3417,7 @@ class DiscriminatorOrPkNoneTest(fixtures.DeclarativeMappedTest):
@classmethod
def insert_data(cls, connection):
Parent, A, B = cls.classes("Parent", "A", "B")
- s = Session()
+ s = fixture_session()
p1 = Parent(id=1)
p2 = Parent(id=2)
@@ -3443,7 +3442,7 @@ class DiscriminatorOrPkNoneTest(fixtures.DeclarativeMappedTest):
def test_pk_is_null(self):
Parent, A = self.classes("Parent", "A")
- sess = Session()
+ sess = fixture_session()
q = (
sess.query(Parent, A)
.select_from(Parent)
@@ -3457,7 +3456,7 @@ class DiscriminatorOrPkNoneTest(fixtures.DeclarativeMappedTest):
def test_pk_not_null_discriminator_null_from_base(self):
(A,) = self.classes("A")
- sess = Session()
+ sess = fixture_session()
q = sess.query(A).filter(A.id == 3)
assert_raises_message(
sa_exc.InvalidRequestError,
@@ -3470,7 +3469,7 @@ class DiscriminatorOrPkNoneTest(fixtures.DeclarativeMappedTest):
def test_pk_not_null_discriminator_null_from_sub(self):
(B,) = self.classes("B")
- sess = Session()
+ sess = fixture_session()
q = sess.query(B).filter(B.id == 4)
assert_raises_message(
sa_exc.InvalidRequestError,
@@ -3528,7 +3527,7 @@ class UnexpectedPolymorphicIdentityTest(fixtures.DeclarativeMappedTest):
ASingleSubA, ASingleSubB, AJoinedSubA, AJoinedSubB = cls.classes(
"ASingleSubA", "ASingleSubB", "AJoinedSubA", "AJoinedSubB"
)
- s = Session()
+ s = fixture_session()
s.add_all([ASingleSubA(), ASingleSubB(), AJoinedSubA(), AJoinedSubB()])
s.commit()
@@ -3536,7 +3535,7 @@ class UnexpectedPolymorphicIdentityTest(fixtures.DeclarativeMappedTest):
def test_single_invalid_ident(self):
ASingle, ASingleSubA = self.classes("ASingle", "ASingleSubA")
- s = Session()
+ s = fixture_session()
q = s.query(ASingleSubA).select_entity_from(select(ASingle).subquery())
@@ -3552,7 +3551,7 @@ class UnexpectedPolymorphicIdentityTest(fixtures.DeclarativeMappedTest):
def test_joined_invalid_ident(self):
AJoined, AJoinedSubA = self.classes("AJoined", "AJoinedSubA")
- s = Session()
+ s = fixture_session()
q = s.query(AJoinedSubA).select_entity_from(select(AJoined).subquery())
@@ -3600,7 +3599,7 @@ class NameConflictTest(fixtures.MappedTest):
mapper(
Foo, self.tables.foo, inherits=Content, polymorphic_identity="foo"
)
- sess = create_session()
+ sess = fixture_session()
f = Foo()
f.content_type = "bar"
sess.add(f)
diff --git a/test/orm/inheritance/test_concrete.py b/test/orm/inheritance/test_concrete.py
index e2777e9e9..f2f8d629b 100644
--- a/test/orm/inheritance/test_concrete.py
+++ b/test/orm/inheritance/test_concrete.py
@@ -11,13 +11,12 @@ from sqlalchemy.orm import joinedload
from sqlalchemy.orm import mapper
from sqlalchemy.orm import polymorphic_union
from sqlalchemy.orm import relationship
-from sqlalchemy.orm import sessionmaker
from sqlalchemy.testing import assert_raises
from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
from sqlalchemy.testing import mock
-from sqlalchemy.testing.fixtures import create_session
+from sqlalchemy.testing.fixtures import fixture_session
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
@@ -165,7 +164,7 @@ class ConcreteTest(fixtures.MappedTest):
concrete=True,
polymorphic_identity="engineer",
)
- session = create_session()
+ session = fixture_session()
session.add(Manager("Tom", "knows how to manage things"))
session.add(Engineer("Kurt", "knows how to hack"))
session.flush()
@@ -225,7 +224,7 @@ class ConcreteTest(fixtures.MappedTest):
concrete=True,
polymorphic_identity="hacker",
)
- session = create_session()
+ session = fixture_session()
tom = Manager("Tom", "knows how to manage things")
assert_raises_message(
@@ -348,7 +347,7 @@ class ConcreteTest(fixtures.MappedTest):
polymorphic_identity="engineer",
)
- session = create_session()
+ session = fixture_session()
tom = ManagerWHybrid("Tom", "mgrdata")
# mapping did not impact the engineer_info
@@ -422,7 +421,7 @@ class ConcreteTest(fixtures.MappedTest):
concrete=True,
polymorphic_identity="hacker",
)
- session = create_session()
+ session = fixture_session()
tom = Manager("Tom", "knows how to manage things")
jerry = Engineer("Jerry", "knows how to program")
hacker = Hacker("Kurt", "Badass", "knows how to hack")
@@ -509,7 +508,7 @@ class ConcreteTest(fixtures.MappedTest):
concrete=True,
polymorphic_identity="hacker",
)
- session = create_session()
+ session = fixture_session()
jdoe = Employee("Jdoe")
tom = Manager("Tom", "knows how to manage things")
jerry = Engineer("Jerry", "knows how to program")
@@ -635,7 +634,7 @@ class ConcreteTest(fixtures.MappedTest):
concrete=True,
polymorphic_identity="engineer",
)
- session = create_session()
+ session = fixture_session()
c = Company()
c.employees.append(Manager("Tom", "knows how to manage things"))
c.employees.append(Engineer("Kurt", "knows how to hack"))
@@ -788,7 +787,7 @@ class PropertyInheritanceTest(fixtures.MappedTest):
"many_b": relationship(B, back_populates="some_dest"),
},
)
- sess = sessionmaker()()
+ sess = fixture_session()
dest1 = Dest(name="c1")
dest2 = Dest(name="c2")
a1 = A(some_dest=dest1, aname="a1")
@@ -916,7 +915,7 @@ class PropertyInheritanceTest(fixtures.MappedTest):
},
)
- sess = sessionmaker()()
+ sess = fixture_session()
dest1 = Dest(name="c1")
dest2 = Dest(name="c2")
a1 = A(some_dest=dest1, aname="a1", id=1)
@@ -1021,7 +1020,7 @@ class PropertyInheritanceTest(fixtures.MappedTest):
assert B.some_dest.property.parent is class_mapper(B)
assert A.some_dest.property.parent is class_mapper(A)
- sess = sessionmaker()()
+ sess = fixture_session()
dest1 = Dest(name="d1")
dest2 = Dest(name="d2")
a1 = A(some_dest=dest2, aname="a1")
@@ -1030,7 +1029,7 @@ class PropertyInheritanceTest(fixtures.MappedTest):
sess.add_all([dest1, dest2, c1, a1, b1])
sess.commit()
- sess2 = sessionmaker()()
+ sess2 = fixture_session()
merged_c1 = sess2.merge(c1)
eq_(merged_c1.some_dest.name, "d2")
eq_(merged_c1.some_dest_id, c1.some_dest_id)
@@ -1135,7 +1134,7 @@ class ManyToManyTest(fixtures.MappedTest):
},
)
mapper(Related, related)
- sess = sessionmaker()()
+ sess = fixture_session()
b1, s1, r1, r2, r3 = Base(), Sub(), Related(), Related(), Related()
b1.related.append(r1)
b1.related.append(r2)
@@ -1227,7 +1226,7 @@ class ColKeysTest(fixtures.MappedTest):
concrete=True,
polymorphic_identity="refugee",
)
- sess = create_session()
+ sess = fixture_session()
eq_(sess.get(Refugee, 1).name, "refugee1")
eq_(sess.get(Refugee, 2).name, "refugee2")
eq_(sess.get(Office, 1).name, "office1")
diff --git a/test/orm/inheritance/test_magazine.py b/test/orm/inheritance/test_magazine.py
index 334ed22f3..7f347e40f 100644
--- a/test/orm/inheritance/test_magazine.py
+++ b/test/orm/inheritance/test_magazine.py
@@ -10,9 +10,9 @@ from sqlalchemy.orm import backref
from sqlalchemy.orm import mapper
from sqlalchemy.orm import polymorphic_union
from sqlalchemy.orm import relationship
-from sqlalchemy.orm import Session
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
+from sqlalchemy.testing.fixtures import fixture_session
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
@@ -360,7 +360,7 @@ class MagazineTest(fixtures.MappedTest):
Publication = self.classes.Publication
- session = Session()
+ session = fixture_session()
pub = self._generate_data()
session.add(pub)
diff --git a/test/orm/inheritance/test_manytomany.py b/test/orm/inheritance/test_manytomany.py
index 207ac09c7..f790b11ac 100644
--- a/test/orm/inheritance/test_manytomany.py
+++ b/test/orm/inheritance/test_manytomany.py
@@ -9,7 +9,7 @@ from sqlalchemy.orm import mapper
from sqlalchemy.orm import relationship
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
-from sqlalchemy.testing.fixtures import create_session
+from sqlalchemy.testing.fixtures import fixture_session
class InheritTest(fixtures.MappedTest):
@@ -114,7 +114,7 @@ class InheritTest(fixtures.MappedTest):
login_id="lg1",
)
)
- sess = create_session()
+ sess = fixture_session()
sess.add(g)
sess.flush()
# TODO: put an assertion
@@ -164,7 +164,7 @@ class InheritTest2(fixtures.MappedTest):
print(foo.join(bar).primary_key)
print(class_mapper(Bar).primary_key)
b = Bar("somedata")
- sess = create_session()
+ sess = fixture_session()
sess.add(b)
sess.flush()
sess.expunge_all()
@@ -192,7 +192,7 @@ class InheritTest2(fixtures.MappedTest):
},
)
- sess = create_session()
+ sess = fixture_session()
b = Bar("barfoo")
sess.add(b)
sess.flush()
@@ -304,7 +304,7 @@ class InheritTest3(fixtures.MappedTest):
},
)
- sess = create_session()
+ sess = fixture_session()
b = Bar("bar #1")
sess.add(b)
b.foos.append(Foo("foo #1"))
@@ -352,7 +352,7 @@ class InheritTest3(fixtures.MappedTest):
},
)
- sess = create_session()
+ sess = fixture_session()
f1 = Foo("foo #1")
b1 = Bar("bar #1")
b2 = Bar("bar #2")
diff --git a/test/orm/inheritance/test_poly_linked_list.py b/test/orm/inheritance/test_poly_linked_list.py
index 83c3e75a0..d5305c473 100644
--- a/test/orm/inheritance/test_poly_linked_list.py
+++ b/test/orm/inheritance/test_poly_linked_list.py
@@ -8,7 +8,7 @@ from sqlalchemy.orm import configure_mappers
from sqlalchemy.orm import mapper
from sqlalchemy.orm import relationship
from sqlalchemy.testing import fixtures
-from sqlalchemy.testing.fixtures import create_session
+from sqlalchemy.testing.fixtures import fixture_session
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
@@ -211,7 +211,7 @@ class PolymorphicCircularTest(fixtures.MappedTest):
)
def _testlist(self, classes):
- sess = create_session()
+ sess = fixture_session()
# create objects in a linked list
count = 1
diff --git a/test/orm/inheritance/test_poly_loading.py b/test/orm/inheritance/test_poly_loading.py
index d7040e822..2f31ab0c4 100644
--- a/test/orm/inheritance/test_poly_loading.py
+++ b/test/orm/inheritance/test_poly_loading.py
@@ -16,6 +16,7 @@ from sqlalchemy.testing.assertsql import AllOf
from sqlalchemy.testing.assertsql import CompiledSQL
from sqlalchemy.testing.assertsql import EachOf
from sqlalchemy.testing.assertsql import Or
+from sqlalchemy.testing.fixtures import fixture_session
from ._poly_fixtures import _Polymorphic
from ._poly_fixtures import Company
from ._poly_fixtures import Engineer
@@ -145,7 +146,7 @@ class LoadBaseAndSubWEagerRelOpt(
def test_load(self):
A, B, ASub, C = self.classes("A", "B", "ASub", "C")
- s = Session()
+ s = fixture_session()
q = (
s.query(A)
@@ -169,7 +170,7 @@ class LoadBaseAndSubWEagerRelMapped(
def test_load(self):
A, B, ASub, C = self.classes("A", "B", "ASub", "C")
- s = Session()
+ s = fixture_session()
q = (
s.query(A)
@@ -182,7 +183,7 @@ class LoadBaseAndSubWEagerRelMapped(
class FixtureLoadTest(_Polymorphic, testing.AssertsExecutionResults):
def test_person_selectin_subclasses(self):
- s = Session()
+ s = fixture_session()
q = s.query(Person).options(
selectin_polymorphic(Person, [Engineer, Manager])
)
@@ -228,7 +229,7 @@ class FixtureLoadTest(_Polymorphic, testing.AssertsExecutionResults):
eq_(result, self.all_employees)
def test_load_company_plus_employees(self):
- s = Session()
+ s = fixture_session()
q = (
s.query(Company)
.options(
@@ -316,7 +317,7 @@ class TestGeometries(GeometryFixtureBase):
)
a, b, c, d, e = self.classes("a", "b", "c", "d", "e")
- sess = Session()
+ sess = fixture_session()
sess.add_all([d(d_data="d1"), e(e_data="e1")])
sess.commit()
@@ -370,7 +371,7 @@ class TestGeometries(GeometryFixtureBase):
)
a, b, c, d, e = self.classes("a", "b", "c", "d", "e")
- sess = Session()
+ sess = fixture_session()
sess.add_all([d(d_data="d1"), e(e_data="e1")])
sess.commit()
@@ -420,7 +421,7 @@ class TestGeometries(GeometryFixtureBase):
)
a, b, c, d, e = self.classes("a", "b", "c", "d", "e")
- sess = Session()
+ sess = fixture_session()
sess.add_all([d(d_data="d1"), e(e_data="e1")])
sess.commit()
@@ -507,7 +508,7 @@ class TestGeometries(GeometryFixtureBase):
)
a, a1, a2 = self.classes("a", "a1", "a2")
- sess = Session()
+ sess = fixture_session()
a1_obj = a1()
a2_obj = a2()
@@ -586,7 +587,7 @@ class LoaderOptionsTest(
Parent, ChildSubclass1, Other = self.classes(
"Parent", "ChildSubclass1", "Other"
)
- session = Session(enable_baked_queries=enable_baked)
+ session = fixture_session(enable_baked_queries=enable_baked)
def no_opt():
q = session.query(Parent).options(
diff --git a/test/orm/inheritance/test_poly_persistence.py b/test/orm/inheritance/test_poly_persistence.py
index 99cab870b..c33f3e0de 100644
--- a/test/orm/inheritance/test_poly_persistence.py
+++ b/test/orm/inheritance/test_poly_persistence.py
@@ -14,7 +14,7 @@ from sqlalchemy.testing import assert_raises
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
from sqlalchemy.testing import is_
-from sqlalchemy.testing.fixtures import create_session
+from sqlalchemy.testing.fixtures import fixture_session
from sqlalchemy.testing.schema import Column
@@ -161,7 +161,7 @@ class InsertOrderTest(PolymorphTest):
},
)
- session = create_session()
+ session = fixture_session()
c = Company(name="company1")
c.employees.append(
Manager(
@@ -391,7 +391,7 @@ class RoundTripTest(PolymorphTest):
else:
person_attribute_name = "name"
- session = create_session()
+ session = fixture_session()
dilbert = (
session.query(Engineer)
@@ -429,7 +429,7 @@ class RoundTripTest(PolymorphTest):
self.assert_sql_count(testing.db, go, 3)
def test_baseclass_lookup(self, get_dilbert):
- session = Session()
+ session = fixture_session()
dilbert = get_dilbert(session)
if self.redefine_colprop:
@@ -449,7 +449,7 @@ class RoundTripTest(PolymorphTest):
)
def test_subclass_lookup(self, get_dilbert):
- session = Session()
+ session = fixture_session()
dilbert = get_dilbert(session)
if self.redefine_colprop:
@@ -465,7 +465,7 @@ class RoundTripTest(PolymorphTest):
)
def test_baseclass_base_alias_filter(self, get_dilbert):
- session = Session()
+ session = fixture_session()
dilbert = get_dilbert(session)
# test selecting from the query, joining against
@@ -485,7 +485,7 @@ class RoundTripTest(PolymorphTest):
)
def test_subclass_base_alias_filter(self, get_dilbert):
- session = Session()
+ session = fixture_session()
dilbert = get_dilbert(session)
palias = people.alias("palias")
@@ -501,7 +501,7 @@ class RoundTripTest(PolymorphTest):
)
def test_baseclass_sub_table_filter(self, get_dilbert):
- session = Session()
+ session = fixture_session()
dilbert = get_dilbert(session)
# this unusual test is selecting from the plain people/engineers
@@ -518,7 +518,7 @@ class RoundTripTest(PolymorphTest):
)
def test_subclass_getitem(self, get_dilbert):
- session = Session()
+ session = fixture_session()
dilbert = get_dilbert(session)
is_(
@@ -530,7 +530,7 @@ class RoundTripTest(PolymorphTest):
def test_primary_table_only_for_requery(self):
- session = Session()
+ session = fixture_session()
if self.redefine_colprop:
person_attribute_name = "person_name"
@@ -560,7 +560,7 @@ class RoundTripTest(PolymorphTest):
else:
person_attribute_name = "name"
- session = Session()
+ session = fixture_session()
daboss = Boss(
status="BBB",
diff --git a/test/orm/inheritance/test_polymorphic_rel.py b/test/orm/inheritance/test_polymorphic_rel.py
index 84ef22d52..581fa45fd 100644
--- a/test/orm/inheritance/test_polymorphic_rel.py
+++ b/test/orm/inheritance/test_polymorphic_rel.py
@@ -14,7 +14,7 @@ from sqlalchemy.orm import with_polymorphic
from sqlalchemy.testing import assert_raises
from sqlalchemy.testing import eq_
from sqlalchemy.testing.assertsql import CompiledSQL
-from sqlalchemy.testing.fixtures import create_session
+from sqlalchemy.testing.fixtures import fixture_session
from ._poly_fixtures import _Polymorphic
from ._poly_fixtures import _PolymorphicAliasedJoins
from ._poly_fixtures import _PolymorphicJoins
@@ -68,7 +68,7 @@ class _PolymorphicTestBase(object):
with_polymorphic is used.
"""
- sess = create_session()
+ sess = fixture_session()
def go():
eq_(
@@ -83,7 +83,7 @@ class _PolymorphicTestBase(object):
# For both joinedload() and subqueryload(), if the original q is
# not loading the subclass table, the joinedload doesn't happen.
- sess = create_session()
+ sess = fixture_session()
def go():
eq_(
@@ -99,7 +99,7 @@ class _PolymorphicTestBase(object):
def test_primary_eager_aliasing_subqueryload(self):
# test that subqueryload does not occur because the parent
# row cannot support it
- sess = create_session()
+ sess = fixture_session()
def go():
eq_(
@@ -116,7 +116,7 @@ class _PolymorphicTestBase(object):
def test_primary_eager_aliasing_selectinload(self):
# test that selectinload does not occur because the parent
# row cannot support it
- sess = create_session()
+ sess = fixture_session()
def go():
eq_(
@@ -134,7 +134,7 @@ class _PolymorphicTestBase(object):
# assert the JOINs don't over JOIN
- sess = create_session()
+ sess = fixture_session()
def go():
eq_(
@@ -168,28 +168,28 @@ class _PolymorphicTestBase(object):
For all mappers, ensure the primary key has been calculated as
just the "person_id" column.
"""
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.get(Person, e1.person_id),
Engineer(name="dilbert", primary_language="java"),
)
def test_get_two(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.get(Engineer, e1.person_id),
Engineer(name="dilbert", primary_language="java"),
)
def test_get_three(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.get(Manager, b1.person_id),
Boss(name="pointy haired boss", golf_swing="fore"),
)
def test_multi_join(self):
- sess = create_session()
+ sess = fixture_session()
e = aliased(Person)
c = aliased(Company)
q = (
@@ -230,7 +230,7 @@ class _PolymorphicTestBase(object):
)
def test_multi_join_future(self):
- sess = create_session(future=True)
+ sess = fixture_session(future=True)
e = aliased(Person)
c = aliased(Company)
@@ -279,22 +279,22 @@ class _PolymorphicTestBase(object):
)
def test_filter_on_subclass_one(self):
- sess = create_session()
+ sess = fixture_session()
eq_(sess.query(Engineer).all()[0], Engineer(name="dilbert"))
def test_filter_on_subclass_one_future(self):
- sess = create_session(future=True)
+ sess = fixture_session(future=True)
eq_(
sess.execute(select(Engineer)).scalar(),
Engineer(name="dilbert"),
)
def test_filter_on_subclass_two(self):
- sess = create_session()
+ sess = fixture_session()
eq_(sess.query(Engineer).first(), Engineer(name="dilbert"))
def test_filter_on_subclass_three(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Engineer)
.filter(Engineer.person_id == e1.person_id)
@@ -303,7 +303,7 @@ class _PolymorphicTestBase(object):
)
def test_filter_on_subclass_four(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Manager)
.filter(Manager.person_id == m1.person_id)
@@ -312,7 +312,7 @@ class _PolymorphicTestBase(object):
)
def test_filter_on_subclass_five(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Manager)
.filter(Manager.person_id == b1.person_id)
@@ -321,14 +321,14 @@ class _PolymorphicTestBase(object):
)
def test_filter_on_subclass_six(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Boss).filter(Boss.person_id == b1.person_id).one(),
Boss(name="pointy haired boss"),
)
def test_join_from_polymorphic_nonaliased_one(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Person)
.join("paperwork")
@@ -338,7 +338,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_polymorphic_nonaliased_one_future(self):
- sess = create_session(future=True)
+ sess = fixture_session(future=True)
eq_(
sess.execute(
select(Person)
@@ -352,7 +352,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_polymorphic_nonaliased_two(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Person)
.order_by(Person.person_id)
@@ -363,7 +363,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_polymorphic_nonaliased_three(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Engineer)
.order_by(Person.person_id)
@@ -374,7 +374,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_polymorphic_nonaliased_four(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Person)
.order_by(Person.person_id)
@@ -386,7 +386,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_polymorphic_flag_aliased_one(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Person)
.order_by(Person.person_id)
@@ -397,7 +397,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_polymorphic_flag_aliased_one_future(self):
- sess = create_session(future=True)
+ sess = fixture_session(future=True)
pa = aliased(Paperwork)
eq_(
@@ -414,7 +414,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_polymorphic_explicit_aliased_one(self):
- sess = create_session()
+ sess = fixture_session()
pa = aliased(Paperwork)
eq_(
sess.query(Person)
@@ -426,7 +426,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_polymorphic_flag_aliased_two(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Person)
.order_by(Person.person_id)
@@ -437,7 +437,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_polymorphic_explicit_aliased_two(self):
- sess = create_session()
+ sess = fixture_session()
pa = aliased(Paperwork)
eq_(
sess.query(Person)
@@ -449,7 +449,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_polymorphic_flag_aliased_three(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Engineer)
.order_by(Person.person_id)
@@ -460,7 +460,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_polymorphic_explicit_aliased_three(self):
- sess = create_session()
+ sess = fixture_session()
pa = aliased(Paperwork)
eq_(
sess.query(Engineer)
@@ -472,7 +472,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_polymorphic_aliased_four(self):
- sess = create_session()
+ sess = fixture_session()
pa = aliased(Paperwork)
eq_(
sess.query(Person)
@@ -485,7 +485,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_with_polymorphic_nonaliased_one(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Person)
.with_polymorphic(Manager)
@@ -497,7 +497,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_with_polymorphic_nonaliased_one_future(self):
- sess = create_session(future=True)
+ sess = fixture_session(future=True)
pm = with_polymorphic(Person, [Manager])
eq_(
@@ -514,7 +514,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_with_polymorphic_nonaliased_two(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Person)
.with_polymorphic([Manager, Engineer])
@@ -526,7 +526,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_with_polymorphic_nonaliased_three(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Person)
.with_polymorphic([Manager, Engineer])
@@ -539,7 +539,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_with_polymorphic_flag_aliased_one(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Person)
.with_polymorphic(Manager)
@@ -550,7 +550,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_with_polymorphic_explicit_aliased_one(self):
- sess = create_session()
+ sess = fixture_session()
pa = aliased(Paperwork)
eq_(
sess.query(Person)
@@ -562,7 +562,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_with_polymorphic_flag_aliased_two(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Person)
.with_polymorphic([Manager, Engineer])
@@ -574,7 +574,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_with_polymorphic_explicit_aliased_two(self):
- sess = create_session()
+ sess = fixture_session()
pa = aliased(Paperwork)
eq_(
sess.query(Person)
@@ -587,7 +587,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_with_polymorphic_aliased_three(self):
- sess = create_session()
+ sess = fixture_session()
pa = aliased(Paperwork)
eq_(
@@ -602,7 +602,7 @@ class _PolymorphicTestBase(object):
)
def test_join_to_polymorphic_nonaliased(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.join("employees")
@@ -612,7 +612,7 @@ class _PolymorphicTestBase(object):
)
def test_join_to_polymorphic_flag_aliased(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.join("employees", aliased=True)
@@ -622,7 +622,7 @@ class _PolymorphicTestBase(object):
)
def test_join_to_polymorphic_explicit_aliased(self):
- sess = create_session()
+ sess = fixture_session()
ea = aliased(Person)
eq_(
sess.query(Company)
@@ -633,13 +633,13 @@ class _PolymorphicTestBase(object):
)
def test_polymorphic_any_one(self):
- sess = create_session()
+ sess = fixture_session()
any_ = Company.employees.any(Person.name == "vlad")
eq_(sess.query(Company).filter(any_).all(), [c2])
def test_polymorphic_any_flag_alias_two(self):
- sess = create_session()
+ sess = fixture_session()
# test that the aliasing on "Person" does not bleed into the
# EXISTS clause generated by any()
any_ = Company.employees.any(Person.name == "wally")
@@ -653,7 +653,7 @@ class _PolymorphicTestBase(object):
)
def test_polymorphic_any_explicit_alias_two(self):
- sess = create_session()
+ sess = fixture_session()
# test that the aliasing on "Person" does not bleed into the
# EXISTS clause generated by any()
any_ = Company.employees.any(Person.name == "wally")
@@ -668,7 +668,7 @@ class _PolymorphicTestBase(object):
)
def test_polymorphic_any_three(self):
- sess = create_session()
+ sess = fixture_session()
any_ = Company.employees.any(Person.name == "vlad")
ea = aliased(Person)
eq_(
@@ -681,7 +681,7 @@ class _PolymorphicTestBase(object):
)
def test_polymorphic_any_eight(self):
- sess = create_session()
+ sess = fixture_session()
any_ = Engineer.machines.any(Machine.name == "Commodore 64")
eq_(
sess.query(Person).order_by(Person.person_id).filter(any_).all(),
@@ -689,7 +689,7 @@ class _PolymorphicTestBase(object):
)
def test_polymorphic_any_nine(self):
- sess = create_session()
+ sess = fixture_session()
any_ = Person.paperwork.any(Paperwork.description == "review #2")
eq_(
sess.query(Person).order_by(Person.person_id).filter(any_).all(),
@@ -697,13 +697,13 @@ class _PolymorphicTestBase(object):
)
def test_join_from_columns_or_subclass_one(self):
- sess = create_session()
+ sess = fixture_session()
expected = [("dogbert",), ("pointy haired boss",)]
eq_(sess.query(Manager.name).order_by(Manager.name).all(), expected)
def test_join_from_columns_or_subclass_two(self):
- sess = create_session()
+ sess = fixture_session()
expected = [("dogbert",), ("dogbert",), ("pointy haired boss",)]
eq_(
sess.query(Manager.name)
@@ -714,7 +714,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_columns_or_subclass_three(self):
- sess = create_session()
+ sess = fixture_session()
expected = [
("dilbert",),
("dilbert",),
@@ -734,7 +734,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_columns_or_subclass_four(self):
- sess = create_session()
+ sess = fixture_session()
# Load Person.name, joining from Person -> paperwork, get all
# the people.
expected = [
@@ -756,7 +756,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_columns_or_subclass_five(self):
- sess = create_session()
+ sess = fixture_session()
# same, on manager. get only managers.
expected = [("dogbert",), ("dogbert",), ("pointy haired boss",)]
eq_(
@@ -768,7 +768,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_columns_or_subclass_six(self):
- sess = create_session()
+ sess = fixture_session()
if self.select_type == "":
# this now raises, due to [ticket:1892]. Manager.person_id
# is now the "person_id" column on Manager. SQL is incorrect.
@@ -813,7 +813,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_columns_or_subclass_seven(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Manager)
.join(Paperwork, Manager.paperwork)
@@ -823,7 +823,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_columns_or_subclass_eight(self):
- sess = create_session()
+ sess = fixture_session()
expected = [("dogbert",), ("dogbert",), ("pointy haired boss",)]
eq_(
sess.query(Manager.name)
@@ -834,7 +834,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_columns_or_subclass_nine(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Manager.person_id)
.join(paperwork, Manager.person_id == paperwork.c.person_id)
@@ -844,7 +844,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_columns_or_subclass_ten(self):
- sess = create_session()
+ sess = fixture_session()
expected = [
("pointy haired boss", "review #1"),
("dogbert", "review #2"),
@@ -859,7 +859,7 @@ class _PolymorphicTestBase(object):
)
def test_join_from_columns_or_subclass_eleven(self):
- sess = create_session()
+ sess = fixture_session()
expected = [("pointy haired boss",), ("dogbert",), ("dogbert",)]
malias = aliased(Manager)
eq_(
@@ -870,7 +870,7 @@ class _PolymorphicTestBase(object):
)
def test_subclass_option_pathing(self):
- sess = create_session()
+ sess = fixture_session()
dilbert = (
sess.query(Person)
.options(defaultload(Engineer.machines).defer(Machine.name))
@@ -887,7 +887,7 @@ class _PolymorphicTestBase(object):
the select_table mapper.
"""
- sess = create_session()
+ sess = fixture_session()
name = "dogbert"
m1 = sess.query(Manager).filter(Manager.name == name).one()
@@ -900,7 +900,7 @@ class _PolymorphicTestBase(object):
assert m2.golf_swing == "fore"
def test_with_polymorphic_one(self):
- sess = create_session()
+ sess = fixture_session()
def go():
eq_(
@@ -914,7 +914,7 @@ class _PolymorphicTestBase(object):
self.assert_sql_count(testing.db, go, 1)
def test_with_polymorphic_two(self):
- sess = create_session()
+ sess = fixture_session()
def go():
eq_(
@@ -928,7 +928,7 @@ class _PolymorphicTestBase(object):
self.assert_sql_count(testing.db, go, 1)
def test_with_polymorphic_three(self):
- sess = create_session()
+ sess = fixture_session()
def go():
eq_(
@@ -942,7 +942,7 @@ class _PolymorphicTestBase(object):
self.assert_sql_count(testing.db, go, 3)
def test_with_polymorphic_four(self):
- sess = create_session()
+ sess = fixture_session()
def go():
eq_(
@@ -956,7 +956,7 @@ class _PolymorphicTestBase(object):
self.assert_sql_count(testing.db, go, 3)
def test_with_polymorphic_five(self):
- sess = create_session()
+ sess = fixture_session()
def go():
# limit the polymorphic join down to just "Person",
@@ -969,7 +969,7 @@ class _PolymorphicTestBase(object):
self.assert_sql_count(testing.db, go, 6)
def test_with_polymorphic_six(self):
- sess = create_session()
+ sess = fixture_session()
assert_raises(
sa_exc.InvalidRequestError,
@@ -988,7 +988,7 @@ class _PolymorphicTestBase(object):
)
def test_with_polymorphic_seven(self):
- sess = create_session()
+ sess = fixture_session()
# compare to entities without related collections to prevent
# additional lazy SQL from firing on loaded entities
eq_(
@@ -1001,7 +1001,7 @@ class _PolymorphicTestBase(object):
def test_relationship_to_polymorphic_one(self):
expected = self._company_with_emps_machines_fixture()
- sess = create_session()
+ sess = fixture_session()
def go():
# test load Companies with lazy load to 'employees'
@@ -1012,7 +1012,7 @@ class _PolymorphicTestBase(object):
def test_relationship_to_polymorphic_two(self):
expected = self._company_with_emps_machines_fixture()
- sess = create_session()
+ sess = fixture_session()
def go():
# with #2438, of_type() is recognized. This
@@ -1040,9 +1040,9 @@ class _PolymorphicTestBase(object):
def test_relationship_to_polymorphic_three(self):
expected = self._company_with_emps_machines_fixture()
- sess = create_session()
+ sess = fixture_session()
- sess = create_session()
+ sess = fixture_session()
def go():
eq_(
@@ -1072,7 +1072,7 @@ class _PolymorphicTestBase(object):
self.assert_sql_count(testing.db, go, count)
def test_joinedload_on_subclass(self):
- sess = create_session()
+ sess = fixture_session()
expected = [
Engineer(
name="dilbert",
@@ -1100,7 +1100,7 @@ class _PolymorphicTestBase(object):
self.assert_sql_count(testing.db, go, 1)
def test_subqueryload_on_subclass(self):
- sess = create_session()
+ sess = fixture_session()
expected = [
Engineer(
name="dilbert",
@@ -1140,12 +1140,12 @@ class _PolymorphicTestBase(object):
self.assert_sql_count(testing.db, go, 2)
def test_query_subclass_join_to_base_relationship(self):
- sess = create_session()
+ sess = fixture_session()
# non-polymorphic
eq_(sess.query(Engineer).join(Person.paperwork).all(), [e1, e2, e3])
def test_join_to_subclass(self):
- sess = create_session()
+ sess = fixture_session()
# TODO: these should all be deprecated (?) - these joins are on the
# core tables and should not be getting adapted, not sure why
@@ -1161,7 +1161,7 @@ class _PolymorphicTestBase(object):
)
def test_join_to_subclass_one(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.select_from(companies.join(people).join(engineers))
@@ -1171,7 +1171,7 @@ class _PolymorphicTestBase(object):
)
def test_join_to_subclass_two(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.join(people.join(engineers), "employees")
@@ -1181,7 +1181,7 @@ class _PolymorphicTestBase(object):
)
def test_join_to_subclass_three(self):
- sess = create_session()
+ sess = fixture_session()
ealias = aliased(Engineer)
eq_(
sess.query(Company)
@@ -1192,7 +1192,7 @@ class _PolymorphicTestBase(object):
)
def test_join_to_subclass_six(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.join(people.join(engineers), "employees")
@@ -1202,7 +1202,7 @@ class _PolymorphicTestBase(object):
)
def test_join_to_subclass_six_point_five(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.join(people.join(engineers), "employees")
@@ -1213,7 +1213,7 @@ class _PolymorphicTestBase(object):
)
def test_join_to_subclass_seven(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.join(people.join(engineers), "employees")
@@ -1224,11 +1224,11 @@ class _PolymorphicTestBase(object):
)
def test_join_to_subclass_eight(self):
- sess = create_session()
+ sess = fixture_session()
eq_(sess.query(Person).join(Engineer.machines).all(), [e1, e2, e3])
def test_join_to_subclass_nine(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.select_from(companies.join(people).join(engineers))
@@ -1238,7 +1238,7 @@ class _PolymorphicTestBase(object):
)
def test_join_to_subclass_ten(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.join("employees")
@@ -1248,7 +1248,7 @@ class _PolymorphicTestBase(object):
)
def test_join_to_subclass_eleven(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.select_from(companies.join(people).join(engineers))
@@ -1258,11 +1258,11 @@ class _PolymorphicTestBase(object):
)
def test_join_to_subclass_twelve(self):
- sess = create_session()
+ sess = fixture_session()
eq_(sess.query(Person).join(Engineer.machines).all(), [e1, e2, e3])
def test_join_to_subclass_thirteen(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Person)
.join(Engineer.machines)
@@ -1272,14 +1272,14 @@ class _PolymorphicTestBase(object):
)
def test_join_to_subclass_fourteen(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company).join("employees", Engineer.machines).all(),
[c1, c2],
)
def test_join_to_subclass_fifteen(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.join("employees", Engineer.machines)
@@ -1289,12 +1289,12 @@ class _PolymorphicTestBase(object):
)
def test_join_to_subclass_sixteen(self):
- sess = create_session()
+ sess = fixture_session()
# non-polymorphic
eq_(sess.query(Engineer).join(Engineer.machines).all(), [e1, e2, e3])
def test_join_to_subclass_seventeen(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Engineer)
.join(Engineer.machines)
@@ -1304,7 +1304,7 @@ class _PolymorphicTestBase(object):
)
def test_join_and_thru_polymorphic_nonaliased_one(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.join(Company.employees)
@@ -1314,7 +1314,7 @@ class _PolymorphicTestBase(object):
)
def test_join_and_thru_polymorphic_aliased_one(self):
- sess = create_session()
+ sess = fixture_session()
ea = aliased(Person)
pa = aliased(Paperwork)
eq_(
@@ -1326,7 +1326,7 @@ class _PolymorphicTestBase(object):
)
def test_join_through_polymorphic_nonaliased_one(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.join(Company.employees)
@@ -1337,7 +1337,7 @@ class _PolymorphicTestBase(object):
)
def test_join_through_polymorphic_nonaliased_two(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.join(Company.employees)
@@ -1348,7 +1348,7 @@ class _PolymorphicTestBase(object):
)
def test_join_through_polymorphic_nonaliased_three(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.join(Company.employees)
@@ -1360,7 +1360,7 @@ class _PolymorphicTestBase(object):
)
def test_join_through_polymorphic_nonaliased_four(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.join(Company.employees)
@@ -1372,7 +1372,7 @@ class _PolymorphicTestBase(object):
)
def test_join_through_polymorphic_nonaliased_five(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.join("employees")
@@ -1384,7 +1384,7 @@ class _PolymorphicTestBase(object):
)
def test_join_through_polymorphic_nonaliased_six(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Company)
.join("employees")
@@ -1396,7 +1396,7 @@ class _PolymorphicTestBase(object):
)
def test_join_through_polymorphic_aliased_one(self):
- sess = create_session()
+ sess = fixture_session()
ea = aliased(Person)
pa = aliased(Paperwork)
eq_(
@@ -1409,7 +1409,7 @@ class _PolymorphicTestBase(object):
)
def test_join_through_polymorphic_aliased_two(self):
- sess = create_session()
+ sess = fixture_session()
ea = aliased(Person)
pa = aliased(Paperwork)
eq_(
@@ -1422,7 +1422,7 @@ class _PolymorphicTestBase(object):
)
def test_join_through_polymorphic_aliased_three(self):
- sess = create_session()
+ sess = fixture_session()
ea = aliased(Person)
pa = aliased(Paperwork)
eq_(
@@ -1436,7 +1436,7 @@ class _PolymorphicTestBase(object):
)
def test_join_through_polymorphic_aliased_four(self):
- sess = create_session()
+ sess = fixture_session()
ea = aliased(Person)
pa = aliased(Paperwork)
eq_(
@@ -1450,7 +1450,7 @@ class _PolymorphicTestBase(object):
)
def test_join_through_polymorphic_aliased_five(self):
- sess = create_session()
+ sess = fixture_session()
ea = aliased(Person)
pa = aliased(Paperwork)
eq_(
@@ -1464,7 +1464,7 @@ class _PolymorphicTestBase(object):
)
def test_join_through_polymorphic_aliased_six(self):
- sess = create_session()
+ sess = fixture_session()
pa = aliased(Paperwork)
ea = aliased(Person)
eq_(
@@ -1478,7 +1478,7 @@ class _PolymorphicTestBase(object):
)
def test_explicit_polymorphic_join_one(self):
- sess = create_session()
+ sess = fixture_session()
# join from Company to Engineer; join condition formulated by
# ORMJoin using regular table foreign key connections. Engineer
@@ -1493,7 +1493,7 @@ class _PolymorphicTestBase(object):
)
def test_explicit_polymorphic_join_two(self):
- sess = create_session()
+ sess = fixture_session()
# same, using explicit join condition. Query.join() must
# adapt the on clause here to match the subquery wrapped around
@@ -1507,7 +1507,7 @@ class _PolymorphicTestBase(object):
)
def test_filter_on_baseclass(self):
- sess = create_session()
+ sess = fixture_session()
eq_(sess.query(Person).order_by(Person.person_id).all(), all_employees)
eq_(
sess.query(Person).order_by(Person.person_id).first(),
@@ -1522,7 +1522,7 @@ class _PolymorphicTestBase(object):
)
def test_from_alias(self):
- sess = create_session()
+ sess = fixture_session()
palias = aliased(Person)
eq_(
sess.query(palias)
@@ -1533,7 +1533,7 @@ class _PolymorphicTestBase(object):
)
def test_self_referential_one(self):
- sess = create_session()
+ sess = fixture_session()
palias = aliased(Person)
expected = [(m1, e1), (m1, e2), (m1, b1)]
@@ -1549,7 +1549,7 @@ class _PolymorphicTestBase(object):
def test_self_referential_two(self):
- sess = create_session()
+ sess = fixture_session()
palias = aliased(Person)
expected = [(m1, e1), (m1, e2), (m1, b1)]
@@ -1567,7 +1567,7 @@ class _PolymorphicTestBase(object):
def test_self_referential_two_point_five(self):
"""Using two aliases, the above case works."""
- sess = create_session()
+ sess = fixture_session()
palias = aliased(Person)
palias2 = aliased(Person)
@@ -1588,7 +1588,7 @@ class _PolymorphicTestBase(object):
def test_self_referential_two_future(self):
# TODO: this is the SECOND test *EVER* of an aliased class of
# an aliased class.
- sess = create_session(future=True)
+ sess = fixture_session(future=True)
expected = [(m1, e1), (m1, e2), (m1, b1)]
# not aliasing the first class
@@ -1618,7 +1618,7 @@ class _PolymorphicTestBase(object):
# TODO: this is the first test *EVER* of an aliased class of
# an aliased class. we should add many more tests for this.
# new case added in Id810f485c5f7ed971529489b84694e02a3356d6d
- sess = create_session(future=True)
+ sess = fixture_session(future=True)
expected = [(m1, e1), (m1, e2), (m1, b1)]
# aliasing the first class
@@ -1648,7 +1648,7 @@ class _PolymorphicTestBase(object):
# second "filter" from hitting it, which would pollute the
# subquery and usually results in recursion overflow errors
# within the adaption.
- sess = create_session()
+ sess = fixture_session()
subq = (
sess.query(engineers.c.person_id)
.filter(Engineer.primary_language == "java")
@@ -1658,7 +1658,7 @@ class _PolymorphicTestBase(object):
eq_(sess.query(Person).filter(Person.person_id.in_(subq)).one(), e1)
def test_mixed_entities_one(self):
- sess = create_session()
+ sess = fixture_session()
expected = [
(
@@ -1744,7 +1744,7 @@ class _PolymorphicTestBase(object):
_join_to_poly_wp_three,
)
def test_mixed_entities_join_to_poly(self, q):
- sess = create_session()
+ sess = fixture_session()
expected = [
("dilbert", "MegaCorp, Inc."),
("wally", "MegaCorp, Inc."),
@@ -1758,7 +1758,7 @@ class _PolymorphicTestBase(object):
)
def test_mixed_entities_two(self):
- sess = create_session()
+ sess = fixture_session()
expected = [
("java", "MegaCorp, Inc."),
("cobol", "Elbonia, Inc."),
@@ -1774,7 +1774,7 @@ class _PolymorphicTestBase(object):
)
def test_mixed_entities_three(self):
- sess = create_session()
+ sess = fixture_session()
palias = aliased(Person)
expected = [
(
@@ -1807,7 +1807,7 @@ class _PolymorphicTestBase(object):
)
def test_mixed_entities_four(self):
- sess = create_session()
+ sess = fixture_session()
palias = aliased(Person)
expected = [
(
@@ -1841,7 +1841,7 @@ class _PolymorphicTestBase(object):
)
def test_mixed_entities_five(self):
- sess = create_session()
+ sess = fixture_session()
palias = aliased(Person)
expected = [("vlad", "Elbonia, Inc.", "dilbert")]
eq_(
@@ -1855,7 +1855,7 @@ class _PolymorphicTestBase(object):
)
def test_mixed_entities_six(self):
- sess = create_session()
+ sess = fixture_session()
palias = aliased(Person)
expected = [
("manager", "dogbert", "engineer", "dilbert"),
@@ -1873,7 +1873,7 @@ class _PolymorphicTestBase(object):
)
def test_mixed_entities_seven(self):
- sess = create_session()
+ sess = fixture_session()
expected = [
("dilbert", "tps report #1"),
("dilbert", "tps report #2"),
@@ -1893,7 +1893,7 @@ class _PolymorphicTestBase(object):
)
def test_mixed_entities_eight(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(func.count(Person.person_id))
.filter(Engineer.primary_language == "java")
@@ -1902,7 +1902,7 @@ class _PolymorphicTestBase(object):
)
def test_mixed_entities_nine(self):
- sess = create_session()
+ sess = fixture_session()
expected = [("Elbonia, Inc.", 1), ("MegaCorp, Inc.", 4)]
eq_(
sess.query(Company.name, func.count(Person.person_id))
@@ -1914,7 +1914,7 @@ class _PolymorphicTestBase(object):
)
def test_mixed_entities_ten(self):
- sess = create_session()
+ sess = fixture_session()
expected = [("Elbonia, Inc.", 1), ("MegaCorp, Inc.", 4)]
eq_(
sess.query(Company.name, func.count(Person.person_id))
@@ -1926,7 +1926,7 @@ class _PolymorphicTestBase(object):
)
# def test_mixed_entities(self):
- # sess = create_session()
+ # sess = fixture_session()
# TODO: I think raise error on these for now. different
# inheritance/loading schemes have different results here,
# all incorrect
@@ -1936,7 +1936,7 @@ class _PolymorphicTestBase(object):
# [])
# def test_mixed_entities(self):
- # sess = create_session()
+ # sess = fixture_session()
# eq_(sess.query(
# Person.name,
# Engineer.primary_language,
@@ -1945,7 +1945,7 @@ class _PolymorphicTestBase(object):
# [])
def test_mixed_entities_eleven(self):
- sess = create_session()
+ sess = fixture_session()
expected = [("java",), ("c++",), ("cobol",)]
eq_(
sess.query(Engineer.primary_language)
@@ -1955,7 +1955,7 @@ class _PolymorphicTestBase(object):
)
def test_mixed_entities_twelve(self):
- sess = create_session()
+ sess = fixture_session()
expected = [("vlad", "Elbonia, Inc.")]
eq_(
sess.query(Person.name, Company.name)
@@ -1966,12 +1966,12 @@ class _PolymorphicTestBase(object):
)
def test_mixed_entities_thirteen(self):
- sess = create_session()
+ sess = fixture_session()
expected = [("pointy haired boss", "fore")]
eq_(sess.query(Boss.name, Boss.golf_swing).all(), expected)
def test_mixed_entities_fourteen(self):
- sess = create_session()
+ sess = fixture_session()
expected = [("dilbert", "java"), ("wally", "c++"), ("vlad", "cobol")]
eq_(
sess.query(Engineer.name, Engineer.primary_language).all(),
@@ -1979,7 +1979,7 @@ class _PolymorphicTestBase(object):
)
def test_mixed_entities_fifteen(self):
- sess = create_session()
+ sess = fixture_session()
expected = [
(
@@ -2001,7 +2001,7 @@ class _PolymorphicTestBase(object):
)
def test_mixed_entities_sixteen(self):
- sess = create_session()
+ sess = fixture_session()
expected = [
(
Engineer(
@@ -2022,17 +2022,17 @@ class _PolymorphicTestBase(object):
)
def test_mixed_entities_seventeen(self):
- sess = create_session()
+ sess = fixture_session()
expected = [("pointy haired boss",), ("dogbert",)]
eq_(sess.query(Manager.name).all(), expected)
def test_mixed_entities_eighteen(self):
- sess = create_session()
+ sess = fixture_session()
expected = [("pointy haired boss foo",), ("dogbert foo",)]
eq_(sess.query(Manager.name + " foo").all(), expected)
def test_mixed_entities_nineteen(self):
- sess = create_session()
+ sess = fixture_session()
row = (
sess.query(Engineer.name, Engineer.primary_language)
.filter(Engineer.name == "dilbert")
@@ -2042,7 +2042,7 @@ class _PolymorphicTestBase(object):
assert row.primary_language == "java"
def test_correlation_one(self):
- sess = create_session()
+ sess = fixture_session()
# this for a long time did not work with PolymorphicAliased and
# PolymorphicUnions, which was due to the no_replacement_traverse
@@ -2063,7 +2063,7 @@ class _PolymorphicTestBase(object):
)
def test_correlation_two(self):
- sess = create_session()
+ sess = fixture_session()
paliased = aliased(Person)
@@ -2081,7 +2081,7 @@ class _PolymorphicTestBase(object):
)
def test_correlation_three(self):
- sess = create_session()
+ sess = fixture_session()
paliased = aliased(Person, flat=True)
@@ -2101,7 +2101,7 @@ class _PolymorphicTestBase(object):
class PolymorphicTest(_PolymorphicTestBase, _Polymorphic):
def test_join_to_subclass_four(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Person)
.select_from(people.join(engineers))
@@ -2111,7 +2111,7 @@ class PolymorphicTest(_PolymorphicTestBase, _Polymorphic):
)
def test_join_to_subclass_five(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Person)
.select_from(people.join(engineers))
@@ -2123,7 +2123,7 @@ class PolymorphicTest(_PolymorphicTestBase, _Polymorphic):
def test_correlation_w_polymorphic(self):
- sess = create_session()
+ sess = fixture_session()
p_poly = with_polymorphic(Person, "*")
@@ -2142,7 +2142,7 @@ class PolymorphicTest(_PolymorphicTestBase, _Polymorphic):
def test_correlation_w_polymorphic_flat(self):
- sess = create_session()
+ sess = fixture_session()
p_poly = with_polymorphic(Person, "*", flat=True)
@@ -2184,7 +2184,7 @@ class PolymorphicPolymorphicTest(
# aliased(polymorphic) will normally do the old-school
# "(SELECT * FROM a JOIN b ...) AS anon_1" thing.
# this is the safest
- sess = create_session()
+ sess = fixture_session()
palias = aliased(Person)
self.assert_compile(
sess.query(palias, Company.name)
@@ -2235,7 +2235,7 @@ class PolymorphicPolymorphicTest(
)
def test_flat_aliased_w_select_from(self):
- sess = create_session()
+ sess = fixture_session()
palias = aliased(Person, flat=True)
self.assert_compile(
sess.query(palias, Company.name)
@@ -2275,7 +2275,7 @@ class PolymorphicPolymorphicTest(
class PolymorphicUnionsTest(_PolymorphicTestBase, _PolymorphicUnions):
def test_subqueryload_on_subclass_uses_path_correctly(self):
- sess = create_session()
+ sess = fixture_session()
expected = [
Engineer(
name="dilbert",
@@ -2361,7 +2361,7 @@ class PolymorphicAliasedJoinsTest(
class PolymorphicJoinsTest(_PolymorphicTestBase, _PolymorphicJoins):
def test_having_group_by(self):
- sess = create_session()
+ sess = fixture_session()
eq_(
sess.query(Person.name)
.group_by(Person.name)
diff --git a/test/orm/inheritance/test_productspec.py b/test/orm/inheritance/test_productspec.py
index 35c7565fb..e940cb0f4 100644
--- a/test/orm/inheritance/test_productspec.py
+++ b/test/orm/inheritance/test_productspec.py
@@ -11,7 +11,7 @@ from sqlalchemy.orm import deferred
from sqlalchemy.orm import mapper
from sqlalchemy.orm import relationship
from sqlalchemy.testing import fixtures
-from sqlalchemy.testing.fixtures import create_session
+from sqlalchemy.testing.fixtures import fixture_session
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
@@ -174,7 +174,7 @@ class InheritTest(fixtures.MappedTest):
),
)
- session = create_session()
+ session = fixture_session()
a1 = Assembly(name="a1")
@@ -223,7 +223,7 @@ class InheritTest(fixtures.MappedTest):
),
)
- session = create_session()
+ session = fixture_session()
s = SpecLine(follower=Product(name="p1"))
s2 = SpecLine(follower=Detail(name="d1"))
@@ -300,7 +300,7 @@ class InheritTest(fixtures.MappedTest):
polymorphic_identity="raster_document",
)
- session = create_session()
+ session = fixture_session()
a1 = Assembly(name="a1")
a1.specification.append(SpecLine(follower=Detail(name="d1")))
@@ -359,7 +359,7 @@ class InheritTest(fixtures.MappedTest):
polymorphic_identity="raster_document",
)
- session = create_session()
+ session = fixture_session()
a1 = Assembly(name="a1")
a1.documents.append(RasterDocument("doc2"))
@@ -448,7 +448,7 @@ class InheritTest(fixtures.MappedTest):
mapper(Assembly, inherits=Product, polymorphic_identity="assembly")
- session = create_session()
+ session = fixture_session()
a1 = Assembly(name="a1")
a1.specification.append(SpecLine(follower=Detail(name="d1")))
diff --git a/test/orm/inheritance/test_relationship.py b/test/orm/inheritance/test_relationship.py
index 6879e1465..214be5e9a 100644
--- a/test/orm/inheritance/test_relationship.py
+++ b/test/orm/inheritance/test_relationship.py
@@ -21,7 +21,7 @@ from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
from sqlalchemy.testing import is_
from sqlalchemy.testing.entities import ComparableEntity
-from sqlalchemy.testing.fixtures import create_session
+from sqlalchemy.testing.fixtures import fixture_session
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
@@ -116,7 +116,7 @@ class SelfReferentialTestJoinedToBase(fixtures.MappedTest):
def test_has(self):
p1 = Person(name="dogbert")
e1 = Engineer(name="dilbert", primary_language="java", reports_to=p1)
- sess = create_session()
+ sess = fixture_session()
sess.add(p1)
sess.add(e1)
sess.flush()
@@ -131,7 +131,7 @@ class SelfReferentialTestJoinedToBase(fixtures.MappedTest):
def test_oftype_aliases_in_exists(self):
e1 = Engineer(name="dilbert", primary_language="java")
e2 = Engineer(name="wally", primary_language="c++", reports_to=e1)
- sess = create_session()
+ sess = fixture_session()
sess.add_all([e1, e2])
sess.flush()
eq_(
@@ -148,7 +148,7 @@ class SelfReferentialTestJoinedToBase(fixtures.MappedTest):
def test_join(self):
p1 = Person(name="dogbert")
e1 = Engineer(name="dilbert", primary_language="java", reports_to=p1)
- sess = create_session()
+ sess = fixture_session()
sess.add(p1)
sess.add(e1)
sess.flush()
@@ -242,7 +242,7 @@ class SelfReferentialJ2JTest(fixtures.MappedTest):
def test_has(self):
m1 = Manager(name="dogbert")
e1 = Engineer(name="dilbert", primary_language="java", reports_to=m1)
- sess = create_session()
+ sess = fixture_session()
sess.add(m1)
sess.add(e1)
sess.flush()
@@ -258,7 +258,7 @@ class SelfReferentialJ2JTest(fixtures.MappedTest):
def test_join(self):
m1 = Manager(name="dogbert")
e1 = Engineer(name="dilbert", primary_language="java", reports_to=m1)
- sess = create_session()
+ sess = fixture_session()
sess.add(m1)
sess.add(e1)
sess.flush()
@@ -281,7 +281,7 @@ class SelfReferentialJ2JTest(fixtures.MappedTest):
e2 = Engineer(name="dilbert", primary_language="c++", reports_to=m2)
e3 = Engineer(name="etc", primary_language="c++")
- sess = create_session()
+ sess = fixture_session()
sess.add_all([m1, m2, e1, e2, e3])
sess.flush()
sess.expunge_all()
@@ -318,7 +318,7 @@ class SelfReferentialJ2JTest(fixtures.MappedTest):
e2 = Engineer(name="wally", primary_language="c++", reports_to=m2)
e3 = Engineer(name="etc", primary_language="c++")
- sess = create_session()
+ sess = fixture_session()
sess.add(m1)
sess.add(m2)
sess.add(e1)
@@ -409,13 +409,13 @@ class SelfReferentialJ2JSelfTest(fixtures.MappedTest):
def _two_obj_fixture(self):
e1 = Engineer(name="wally")
e2 = Engineer(name="dilbert", reports_to=e1)
- sess = Session()
+ sess = fixture_session()
sess.add_all([e1, e2])
sess.commit()
return sess
def _five_obj_fixture(self):
- sess = Session()
+ sess = fixture_session()
e1, e2, e3, e4, e5 = [Engineer(name="e%d" % (i + 1)) for i in range(5)]
e3.reports_to = e1
e4.reports_to = e2
@@ -596,7 +596,7 @@ class M2MFilterTest(fixtures.MappedTest):
def test_not_contains(self):
Organization = self.classes.Organization
- sess = create_session()
+ sess = fixture_session()
e1 = sess.query(Person).filter(Engineer.name == "e1").one()
eq_(
@@ -615,7 +615,7 @@ class M2MFilterTest(fixtures.MappedTest):
)
def test_any(self):
- sess = create_session()
+ sess = fixture_session()
Organization = self.classes.Organization
eq_(
@@ -718,7 +718,7 @@ class SelfReferentialM2MTest(fixtures.MappedTest, AssertsCompiledSQL):
def test_query_crit(self):
Child1, Child2 = self.classes.Child1, self.classes.Child2
- sess = create_session()
+ sess = fixture_session()
c11, c12, c13 = Child1(), Child1(), Child1()
c21, c22, c23 = Child2(), Child2(), Child2()
c11.left_child2 = c22
@@ -812,7 +812,7 @@ class SelfReferentialM2MTest(fixtures.MappedTest, AssertsCompiledSQL):
def test_eager_join(self):
Child1, Child2 = self.classes.Child1, self.classes.Child2
- sess = create_session()
+ sess = fixture_session()
c1 = Child1()
c1.left_child2 = Child2()
sess.add(c1)
@@ -849,7 +849,7 @@ class SelfReferentialM2MTest(fixtures.MappedTest, AssertsCompiledSQL):
def test_subquery_load(self):
Child1, Child2 = self.classes.Child1, self.classes.Child2
- sess = create_session()
+ sess = fixture_session()
c1 = Child1()
c1.left_child2 = Child2()
sess.add(c1)
@@ -974,7 +974,7 @@ class EagerToSubclassTest(fixtures.MappedTest):
def test_joinedload(self):
Parent = self.classes.Parent
- sess = Session()
+ sess = fixture_session()
def go():
eq_(
@@ -987,7 +987,7 @@ class EagerToSubclassTest(fixtures.MappedTest):
def test_contains_eager(self):
Parent = self.classes.Parent
Sub = self.classes.Sub
- sess = Session()
+ sess = fixture_session()
def go():
eq_(
@@ -1004,7 +1004,7 @@ class EagerToSubclassTest(fixtures.MappedTest):
def test_subq_through_related(self):
Parent = self.classes.Parent
Base = self.classes.Base
- sess = Session()
+ sess = fixture_session()
def go():
eq_(
@@ -1023,7 +1023,7 @@ class EagerToSubclassTest(fixtures.MappedTest):
Parent = self.classes.Parent
Base = self.classes.Base
pa = aliased(Parent)
- sess = Session()
+ sess = fixture_session()
def go():
eq_(
@@ -1150,7 +1150,7 @@ class SubClassEagerToSubClassTest(fixtures.MappedTest):
def test_joinedload(self):
Subparent = self.classes.Subparent
- sess = create_session()
+ sess = fixture_session()
def go():
eq_(
@@ -1175,7 +1175,7 @@ class SubClassEagerToSubClassTest(fixtures.MappedTest):
def test_contains_eager(self):
Subparent = self.classes.Subparent
- sess = create_session()
+ sess = fixture_session()
def go():
eq_(
@@ -1204,7 +1204,7 @@ class SubClassEagerToSubClassTest(fixtures.MappedTest):
def test_subqueryload(self):
Subparent = self.classes.Subparent
- sess = create_session()
+ sess = fixture_session()
def go():
eq_(
@@ -1336,7 +1336,7 @@ class SameNamedPropTwoPolymorphicSubClassesTest(fixtures.MappedTest):
C = self.classes.C
D = self.classes.D
- session = Session()
+ session = fixture_session()
d = session.query(D).one()
a_poly = with_polymorphic(A, [B, C])
@@ -1354,7 +1354,7 @@ class SameNamedPropTwoPolymorphicSubClassesTest(fixtures.MappedTest):
C = self.classes.C
D = self.classes.D
- session = Session()
+ session = fixture_session()
d = session.query(D).one()
def go():
@@ -1375,7 +1375,7 @@ class SameNamedPropTwoPolymorphicSubClassesTest(fixtures.MappedTest):
C = self.classes.C
D = self.classes.D
- session = Session()
+ session = fixture_session()
d = session.query(D).one()
a_poly = with_polymorphic(A, [B, C])
@@ -1393,7 +1393,7 @@ class SameNamedPropTwoPolymorphicSubClassesTest(fixtures.MappedTest):
C = self.classes.C
D = self.classes.D
- session = Session()
+ session = fixture_session()
d = session.query(D).one()
def go():
@@ -1499,7 +1499,7 @@ class SubClassToSubClassFromParentTest(fixtures.MappedTest):
def test_2617(self):
A = self.classes.A
- session = Session()
+ session = fixture_session()
def go():
a1 = session.query(A).first()
@@ -1642,7 +1642,7 @@ class SubClassToSubClassMultiTest(AssertsCompiledSQL, fixtures.MappedTest):
def test_one(self):
Parent, Base1, Base2, Sub1, Sub2, EP1, EP2 = self._classes()
- s = Session()
+ s = fixture_session()
self.assert_compile(
s.query(Parent)
.join(Parent.sub1, Sub1.sub2)
@@ -1663,7 +1663,7 @@ class SubClassToSubClassMultiTest(AssertsCompiledSQL, fixtures.MappedTest):
s2a = aliased(Sub2, flat=True)
- s = Session()
+ s = fixture_session()
self.assert_compile(
s.query(Parent).join(Parent.sub1).join(s2a, Sub1.sub2),
"SELECT parent.id AS parent_id, parent.data AS parent_data "
@@ -1677,7 +1677,7 @@ class SubClassToSubClassMultiTest(AssertsCompiledSQL, fixtures.MappedTest):
def test_three(self):
Parent, Base1, Base2, Sub1, Sub2, EP1, EP2 = self._classes()
- s = Session()
+ s = fixture_session()
self.assert_compile(
s.query(Base1).join(Base1.sub2).join(Sub2.ep1).join(Sub2.ep2),
"SELECT base1.id AS base1_id, base1.data AS base1_data "
@@ -1691,7 +1691,7 @@ class SubClassToSubClassMultiTest(AssertsCompiledSQL, fixtures.MappedTest):
def test_four(self):
Parent, Base1, Base2, Sub1, Sub2, EP1, EP2 = self._classes()
- s = Session()
+ s = fixture_session()
self.assert_compile(
s.query(Sub2)
.join(Base1, Base1.id == Sub2.base1_id)
@@ -1709,7 +1709,7 @@ class SubClassToSubClassMultiTest(AssertsCompiledSQL, fixtures.MappedTest):
def test_five(self):
Parent, Base1, Base2, Sub1, Sub2, EP1, EP2 = self._classes()
- s = Session()
+ s = fixture_session()
self.assert_compile(
s.query(Sub2)
.join(Sub1, Sub1.id == Sub2.base1_id)
@@ -1729,7 +1729,7 @@ class SubClassToSubClassMultiTest(AssertsCompiledSQL, fixtures.MappedTest):
def test_six_legacy(self):
Parent, Base1, Base2, Sub1, Sub2, EP1, EP2 = self._classes()
- s = Session()
+ s = fixture_session()
# as of from_self() changing in
# I3abfb45dd6e50f84f29d39434caa0b550ce27864,
@@ -1781,7 +1781,7 @@ class SubClassToSubClassMultiTest(AssertsCompiledSQL, fixtures.MappedTest):
def test_seven_legacy(self):
Parent, Base1, Base2, Sub1, Sub2, EP1, EP2 = self._classes()
- s = Session()
+ s = fixture_session()
# as of from_self() changing in
# I3abfb45dd6e50f84f29d39434caa0b550ce27864,
@@ -1946,7 +1946,7 @@ class JoinedloadWPolyOfTypeContinued(
def test_joined_load_lastlink_subclass(self):
Foo, User, SubBar = self.classes("Foo", "User", "SubBar")
- s = Session()
+ s = fixture_session()
foo_polymorphic = with_polymorphic(Foo, "*", aliased=True)
@@ -1992,7 +1992,7 @@ class JoinedloadWPolyOfTypeContinued(
def test_joined_load_lastlink_baseclass(self):
Foo, User, Bar = self.classes("Foo", "User", "Bar")
- s = Session()
+ s = fixture_session()
foo_polymorphic = with_polymorphic(Foo, "*", aliased=True)
@@ -2072,7 +2072,7 @@ class ContainsEagerMultipleOfType(
def test_contains_eager_multi_alias(self):
X, B, A = self.classes("X", "B", "A")
- s = Session()
+ s = fixture_session()
a_b_alias = aliased(B, name="a_b")
b_x_alias = aliased(X, name="b_x")
@@ -2141,7 +2141,7 @@ class JoinedloadSinglePolysubSingle(
def test_query(self):
Thing = self.classes.Thing
- sess = Session()
+ sess = fixture_session()
self.assert_compile(
sess.query(Thing),
"SELECT things.id AS things_id, "
@@ -2281,7 +2281,7 @@ class JoinedloadOverWPolyAliased(
cls = fn()
Link = self.classes.Link
- session = Session()
+ session = fixture_session()
q = session.query(cls).options(
joinedload(cls.links).joinedload(Link.child).joinedload(cls.links)
)
@@ -2310,7 +2310,7 @@ class JoinedloadOverWPolyAliased(
parent_cls = fn()
Link = self.classes.Link
- session = Session()
+ session = fixture_session()
q = session.query(Link).options(
joinedload(Link.child).joinedload(parent_cls.owner)
)
@@ -2341,7 +2341,7 @@ class JoinedloadOverWPolyAliased(
poly = with_polymorphic(Parent, [Sub1])
- session = Session()
+ session = fixture_session()
q = session.query(poly).options(
joinedload(poly.Sub1.links)
.joinedload(Link.child.of_type(Sub1))
@@ -2369,7 +2369,7 @@ class JoinedloadOverWPolyAliased(
poly = with_polymorphic(Parent, [Sub1])
- session = Session()
+ session = fixture_session()
q = session.query(poly).options(
joinedload(poly.Sub1.links, innerjoin=True)
.joinedload(Link.child.of_type(Sub1), innerjoin=True)
@@ -2395,7 +2395,7 @@ class JoinedloadOverWPolyAliased(
Parent = self.classes.Parent
Link = self.classes.Link
- session = Session()
+ session = fixture_session()
session.add_all([Parent(), Parent()])
# represents "Parent" and "Sub1" rows
@@ -2472,7 +2472,7 @@ class JoinAcrossJoinedInhMultiPath(
t1_alias = aliased(Target)
t2_alias = aliased(Target)
- sess = Session()
+ sess = fixture_session()
q = (
sess.query(Root)
.join(s1_alias, Root.sub1)
@@ -2508,7 +2508,7 @@ class JoinAcrossJoinedInhMultiPath(
t1_alias = aliased(Target)
t2_alias = aliased(Target)
- sess = Session()
+ sess = fixture_session()
q = (
sess.query(Root)
.join(s1_alias, Root.sub1)
@@ -2539,7 +2539,7 @@ class JoinAcrossJoinedInhMultiPath(
self.classes.Sub1,
)
- sess = Session()
+ sess = fixture_session()
q = sess.query(Root).options(
joinedload(Root.sub1).joinedload(Sub1.target),
joinedload(Root.intermediate)
@@ -2631,7 +2631,7 @@ class MultipleAdaptUsesEntityOverTableTest(
def _two_join_fixture(self):
B, C, D = (self.classes.B, self.classes.C, self.classes.D)
- s = Session()
+ s = fixture_session()
return (
s.query(B.name, C.name, D.name)
.select_from(B)
@@ -2805,7 +2805,7 @@ class BetweenSubclassJoinWExtraJoinedLoad(
def test_query(self):
Engineer, Manager = self.classes("Engineer", "Manager")
- sess = Session()
+ sess = fixture_session()
# eager join is both from Enginer->LastSeen as well as
# Manager->LastSeen. In the case of Manager->LastSeen,
@@ -2885,7 +2885,7 @@ class M2ODontLoadSiblingTest(fixtures.DeclarativeMappedTest):
def test_load_m2o_emit_query(self):
Other, Child1 = self.classes("Other", "Child1")
- s = Session()
+ s = fixture_session()
obj = s.query(Other).first()
@@ -2894,7 +2894,7 @@ class M2ODontLoadSiblingTest(fixtures.DeclarativeMappedTest):
def test_load_m2o_use_get(self):
Other, Child1 = self.classes("Other", "Child1")
- s = Session()
+ s = fixture_session()
obj = s.query(Other).first()
c1 = s.query(Child1).first()
diff --git a/test/orm/inheritance/test_selects.py b/test/orm/inheritance/test_selects.py
index dab184194..24297dd0e 100644
--- a/test/orm/inheritance/test_selects.py
+++ b/test/orm/inheritance/test_selects.py
@@ -6,6 +6,7 @@ from sqlalchemy.orm import mapper
from sqlalchemy.orm import Session
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
+from sqlalchemy.testing.fixtures import fixture_session
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
@@ -117,7 +118,7 @@ class JoinFromSelectPersistenceTest(fixtures.MappedTest):
)
mapper(Child, child, inherits=Base, polymorphic_identity="child")
- sess = Session()
+ sess = fixture_session()
# 2. use an id other than "1" here so can't rely on
# the two inserts having the same id
diff --git a/test/orm/inheritance/test_single.py b/test/orm/inheritance/test_single.py
index cbe6bd238..11c6bb212 100644
--- a/test/orm/inheritance/test_single.py
+++ b/test/orm/inheritance/test_single.py
@@ -16,14 +16,13 @@ from sqlalchemy.orm import joinedload
from sqlalchemy.orm import mapper
from sqlalchemy.orm import relationship
from sqlalchemy.orm import Session
-from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import subqueryload
from sqlalchemy.orm import with_polymorphic
from sqlalchemy.testing import AssertsCompiledSQL
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
from sqlalchemy.testing.assertsql import CompiledSQL
-from sqlalchemy.testing.fixtures import create_session
+from sqlalchemy.testing.fixtures import fixture_session
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
@@ -126,7 +125,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
self.classes.Engineer,
)
- session = create_session()
+ session = fixture_session()
m1 = Manager(name="Tom", manager_data="knows how to manage things")
e1 = Engineer(name="Kurt", engineer_info="knows how to hack")
@@ -283,7 +282,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
def test_from_self_legacy(self):
Engineer = self.classes.Engineer
- sess = create_session()
+ sess = fixture_session()
with testing.expect_deprecated(r"The Query.from_self\(\) method"):
self.assert_compile(
sess.query(Engineer).from_self(),
@@ -350,7 +349,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
def test_select_from_aliased_w_subclass(self):
Engineer = self.classes.Engineer
- sess = create_session()
+ sess = fixture_session()
a1 = aliased(Engineer)
self.assert_compile(
@@ -369,7 +368,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
def test_union_modifiers(self):
Engineer, Manager = self.classes("Engineer", "Manager")
- sess = create_session()
+ sess = fixture_session()
q1 = sess.query(Engineer).filter(Engineer.engineer_info == "foo")
q2 = sess.query(Manager).filter(Manager.manager_data == "bar")
@@ -420,7 +419,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
Engineer, Manager = self.classes("Engineer", "Manager")
- sess = create_session()
+ sess = fixture_session()
self.assert_compile(
sess.query(Engineer)
@@ -437,7 +436,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
def test_from_self_count(self):
Engineer = self.classes.Engineer
- sess = create_session()
+ sess = fixture_session()
col = func.count(literal_column("*"))
with testing.expect_deprecated(r"The Query.from_self\(\) method"):
self.assert_compile(
@@ -452,7 +451,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
def test_select_from_count(self):
Manager, Engineer = (self.classes.Manager, self.classes.Engineer)
- sess = create_session()
+ sess = fixture_session()
m1 = Manager(name="Tom", manager_data="data1")
e1 = Engineer(name="Kurt", engineer_info="knows how to hack")
sess.add_all([m1, e1])
@@ -468,7 +467,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
self.classes.Engineer,
)
- sess = create_session()
+ sess = fixture_session()
m1 = Manager(name="Tom", manager_data="data1")
m2 = Manager(name="Tom2", manager_data="data2")
e1 = Engineer(name="Kurt", engineer_info="knows how to hack")
@@ -500,7 +499,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
self.classes.Engineer,
)
- sess = create_session()
+ sess = fixture_session()
r1, r2, r3, r4 = (
Report(name="r1"),
Report(name="r2"),
@@ -544,7 +543,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
Manager = self.classes.Manager
Engineer = self.classes.Engineer
- sess = create_session()
+ sess = fixture_session()
m1 = Manager(name="Tom", manager_data="data1")
m2 = Manager(name="Tom2", manager_data="data2")
e1 = Engineer(name="Kurt", engineer_info="data3")
@@ -562,7 +561,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
def test_exists_standalone(self):
Engineer = self.classes.Engineer
- sess = create_session()
+ sess = fixture_session()
self.assert_compile(
sess.query(
@@ -580,7 +579,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
self.classes.Engineer,
)
- sess = create_session()
+ sess = fixture_session()
m1 = Manager(name="Tom", manager_data="data1")
r1 = Report(employee=m1)
@@ -602,7 +601,7 @@ class SingleInheritanceTest(testing.AssertsCompiledSQL, fixtures.MappedTest):
self.classes.Engineer,
)
- sess = create_session()
+ sess = fixture_session()
m1 = Manager(name="Tom", manager_data="data1")
r1 = Report(employee=m1)
@@ -695,7 +694,7 @@ class RelationshipFromSingleTest(
def test_subquery_load(self):
Employee, Stuff, Manager = self.classes("Employee", "Stuff", "Manager")
- sess = create_session()
+ sess = fixture_session()
with self.sql_execution_asserter(testing.db) as asserter:
sess.query(Manager).options(subqueryload("stuff")).all()
@@ -809,7 +808,7 @@ class RelationshipToSingleTest(
inherits=Engineer,
polymorphic_identity="juniorengineer",
)
- sess = sessionmaker()()
+ sess = fixture_session()
c1 = Company(name="c1")
c2 = Company(name="c2")
@@ -851,7 +850,7 @@ class RelationshipToSingleTest(
mapper(Employee, employees, polymorphic_on=employees.c.type)
mapper(Engineer, inherits=Employee, polymorphic_identity="engineer")
- sess = create_session()
+ sess = fixture_session()
self.assert_compile(
sess.query(Company).outerjoin(
Company.employee.of_type(Engineer),
@@ -882,7 +881,7 @@ class RelationshipToSingleTest(
mapper(Employee, employees)
mapper(Engineer, inherits=Employee)
- sess = create_session()
+ sess = fixture_session()
self.assert_compile(
sess.query(Company, Engineer.name).join(
Engineer, Company.company_id == Engineer.company_id
@@ -910,7 +909,7 @@ class RelationshipToSingleTest(
mapper(Employee, employees, polymorphic_on=employees.c.type)
mapper(Engineer, inherits=Employee, polymorphic_identity="engineer")
- sess = create_session()
+ sess = fixture_session()
self.assert_compile(
sess.query(Company, Engineer.name).outerjoin("engineers"),
"SELECT companies.company_id AS companies_company_id, "
@@ -938,7 +937,7 @@ class RelationshipToSingleTest(
mapper(Engineer, inherits=Employee, polymorphic_identity="engineer")
eng_alias = aliased(Engineer)
- sess = create_session()
+ sess = fixture_session()
self.assert_compile(
sess.query(Company, eng_alias.name).outerjoin(
eng_alias, Company.engineers
@@ -967,7 +966,7 @@ class RelationshipToSingleTest(
mapper(Employee, employees, polymorphic_on=employees.c.type)
mapper(Engineer, inherits=Employee, polymorphic_identity="engineer")
- sess = create_session()
+ sess = fixture_session()
self.assert_compile(
sess.query(Company, Engineer).outerjoin(
Engineer, Company.company_id == Engineer.company_id
@@ -1002,7 +1001,7 @@ class RelationshipToSingleTest(
mapper(Engineer, inherits=Employee, polymorphic_identity="engineer")
eng_alias = aliased(Engineer)
- sess = create_session()
+ sess = fixture_session()
self.assert_compile(
sess.query(Company, eng_alias).outerjoin(
eng_alias, Company.company_id == eng_alias.company_id
@@ -1036,7 +1035,7 @@ class RelationshipToSingleTest(
mapper(Employee, employees, polymorphic_on=employees.c.type)
mapper(Engineer, inherits=Employee, polymorphic_identity="engineer")
- sess = create_session()
+ sess = fixture_session()
self.assert_compile(
sess.query(Company, Engineer).outerjoin(Engineer),
"SELECT companies.company_id AS companies_company_id, "
@@ -1069,7 +1068,7 @@ class RelationshipToSingleTest(
mapper(Engineer, inherits=Employee, polymorphic_identity="engineer")
eng_alias = aliased(Engineer)
- sess = create_session()
+ sess = fixture_session()
self.assert_compile(
sess.query(Company, eng_alias).outerjoin(eng_alias),
"SELECT companies.company_id AS companies_company_id, "
@@ -1102,7 +1101,7 @@ class RelationshipToSingleTest(
)
mapper(Engineer, inherits=Employee, polymorphic_identity="engineer")
- sess = create_session()
+ sess = fixture_session()
engineer_count = (
sess.query(func.count(Engineer.employee_id))
.select_from(Engineer)
@@ -1144,7 +1143,7 @@ class RelationshipToSingleTest(
mapper(Engineer, inherits=Employee, polymorphic_identity="engineer")
mapper(Manager, inherits=Employee, polymorphic_identity="manager")
- s = create_session()
+ s = fixture_session()
q1 = (
s.query(Engineer)
@@ -1236,7 +1235,7 @@ class RelationshipToSingleTest(
inherits=Engineer,
polymorphic_identity="juniorengineer",
)
- sess = sessionmaker()()
+ sess = fixture_session()
c1 = Company(name="c1")
c2 = Company(name="c2")
@@ -1433,7 +1432,7 @@ class ManyToManyToSingleTest(fixtures.MappedTest, AssertsCompiledSQL):
Parent = self.classes.Parent
SubChild1 = self.classes.SubChild1
- s = Session()
+ s = fixture_session()
p1 = s.query(Parent).options(joinedload(Parent.s1)).all()[0]
eq_(p1.__dict__["s1"], SubChild1(name="sc1_1"))
@@ -1443,7 +1442,7 @@ class ManyToManyToSingleTest(fixtures.MappedTest, AssertsCompiledSQL):
Child = self.classes.Child
SubChild1 = self.classes.SubChild1
- s = Session()
+ s = fixture_session()
p1, c1 = s.query(Parent, Child).outerjoin(Parent.s1).all()[0]
eq_(c1, SubChild1(name="sc1_1"))
@@ -1452,7 +1451,7 @@ class ManyToManyToSingleTest(fixtures.MappedTest, AssertsCompiledSQL):
Parent = self.classes.Parent
Child = self.classes.Child
- s = Session()
+ s = fixture_session()
self.assert_compile(
s.query(Parent, Child).outerjoin(Parent.s1),
@@ -1468,7 +1467,7 @@ class ManyToManyToSingleTest(fixtures.MappedTest, AssertsCompiledSQL):
def test_assert_joinedload_sql(self):
Parent = self.classes.Parent
- s = Session()
+ s = fixture_session()
self.assert_compile(
s.query(Parent).options(joinedload(Parent.s1)),
@@ -1538,7 +1537,7 @@ class SingleOnJoinedTest(fixtures.MappedTest):
)
mapper(Manager, inherits=Employee, polymorphic_identity="manager")
- sess = create_session()
+ sess = fixture_session()
sess.add(Person(name="p1"))
sess.add(Employee(name="e1", employee_data="ed1"))
sess.add(Manager(name="m1", employee_data="ed2", manager_data="md1"))
@@ -1663,7 +1662,7 @@ class SingleFromPolySelectableTest(
[self.classes.Boss, self.classes.Manager, self.classes.Engineer],
self._with_poly_fixture(),
)
- s = Session()
+ s = fixture_session()
q = s.query(poly.Boss)
self.assert_compile(
q,
@@ -1695,7 +1694,7 @@ class SingleFromPolySelectableTest(
poly = self._with_poly_fixture()
- s = Session()
+ s = fixture_session()
q = s.query(Boss).with_polymorphic(Boss, poly)
self.assert_compile(
q,
@@ -1719,7 +1718,7 @@ class SingleFromPolySelectableTest(
def test_single_inh_subclass_join_joined_inh_subclass(self):
Boss, Engineer = self.classes("Boss", "Engineer")
- s = Session()
+ s = fixture_session()
q = s.query(Boss).join(Engineer, Engineer.manager_id == Boss.id)
@@ -1744,7 +1743,7 @@ class SingleFromPolySelectableTest(
self._with_poly_fixture(),
)
- s = Session()
+ s = fixture_session()
q = s.query(Boss).join(
poly.Engineer, poly.Engineer.manager_id == Boss.id
@@ -1776,7 +1775,7 @@ class SingleFromPolySelectableTest(
def test_joined_inh_subclass_join_single_inh_subclass(self):
Engineer = self.classes.Engineer
Boss = self.classes.Boss
- s = Session()
+ s = fixture_session()
q = s.query(Engineer).join(Boss, Engineer.manager_id == Boss.id)
@@ -1826,7 +1825,7 @@ class EagerDefaultEvalTest(fixtures.DeclarativeMappedTest):
foo = Foo()
- session = Session()
+ session = fixture_session()
session.add(foo)
session.flush()
@@ -1839,7 +1838,7 @@ class EagerDefaultEvalTest(fixtures.DeclarativeMappedTest):
def test_persist_bar(self):
Bar = self.classes.Bar
bar = Bar()
- session = Session()
+ session = fixture_session()
session.add(bar)
session.flush()
diff --git a/test/orm/inheritance/test_with_poly.py b/test/orm/inheritance/test_with_poly.py
index dee76fc7b..2492e593c 100644
--- a/test/orm/inheritance/test_with_poly.py
+++ b/test/orm/inheritance/test_with_poly.py
@@ -2,9 +2,9 @@ from sqlalchemy import and_
from sqlalchemy import exc
from sqlalchemy import or_
from sqlalchemy import testing
-from sqlalchemy.orm import create_session
from sqlalchemy.orm import with_polymorphic
from sqlalchemy.testing import eq_
+from sqlalchemy.testing.fixtures import fixture_session
from ._poly_fixtures import _Polymorphic
from ._poly_fixtures import _PolymorphicAliasedJoins
from ._poly_fixtures import _PolymorphicFixtureBase
@@ -19,7 +19,7 @@ from ._poly_fixtures import Person
class WithPolymorphicAPITest(_Polymorphic, _PolymorphicFixtureBase):
def test_no_use_flat_and_aliased(self):
- sess = create_session()
+ sess = fixture_session()
subq = sess.query(Person).subquery()
@@ -37,7 +37,7 @@ class WithPolymorphicAPITest(_Polymorphic, _PolymorphicFixtureBase):
class _WithPolymorphicBase(_PolymorphicFixtureBase):
def test_join_base_to_sub(self):
- sess = create_session()
+ sess = fixture_session()
pa = with_polymorphic(Person, [Engineer])
def go():
@@ -51,7 +51,7 @@ class _WithPolymorphicBase(_PolymorphicFixtureBase):
self.assert_sql_count(testing.db, go, 1)
def test_col_expression_base_plus_two_subs(self):
- sess = create_session()
+ sess = fixture_session()
pa = with_polymorphic(Person, [Engineer, Manager])
eq_(
@@ -70,7 +70,7 @@ class _WithPolymorphicBase(_PolymorphicFixtureBase):
)
def test_join_to_join_entities(self):
- sess = create_session()
+ sess = fixture_session()
pa = with_polymorphic(Person, [Engineer])
pa_alias = with_polymorphic(Person, [Engineer], aliased=True)
@@ -101,7 +101,7 @@ class _WithPolymorphicBase(_PolymorphicFixtureBase):
)
def test_join_to_join_columns(self):
- sess = create_session()
+ sess = fixture_session()
pa = with_polymorphic(Person, [Engineer])
pa_alias = with_polymorphic(Person, [Engineer], aliased=True)