MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / mapping_fixture

Method mapping_fixture

test/aaa_profiling/test_misc.py:60–101  ·  view source on GitHub ↗
(cls)

Source from the content-addressed store, hash-verified

58 @testing.fixture(scope="class")
59 @classmethod
60 def mapping_fixture(cls):
61 # note in order to work nicely with "fixture" we are emerging
62 # a whole new model of setup/teardown, since pytest "fixture"
63 # sort of purposely works badly with setup/teardown
64
65 registry = sqlalchemy.orm.registry()
66
67 metadata = MetaData()
68 parent = Table(
69 "parent",
70 metadata,
71 Column("id", Integer, primary_key=True),
72 Column("data", String(20)),
73 )
74 child = Table(
75 "child",
76 metadata,
77 Column("id", Integer, primary_key=True),
78 Column("data", String(20)),
79 Column(
80 "parent_id", Integer, ForeignKey("parent.id"), nullable=False
81 ),
82 )
83
84 class Parent(testing.entities.BasicEntity):
85 pass
86
87 class Child(testing.entities.BasicEntity):
88 pass
89
90 registry.map_imperatively(
91 Parent,
92 parent,
93 properties={"children": relationship(Child, backref="parent")},
94 )
95 registry.map_imperatively(Child, child)
96
97 registry.configure()
98
99 yield Parent, Child
100
101 registry.dispose()
102
103 @testing.fixture(scope="function")
104 def stmt_fixture_one(self, mapping_fixture):

Callers

nothing calls this directly

Calls 10

MetaDataClass · 0.90
TableClass · 0.90
ColumnClass · 0.90
StringClass · 0.90
ForeignKeyClass · 0.90
relationshipFunction · 0.90
registryMethod · 0.80
map_imperativelyMethod · 0.80
configureMethod · 0.45
disposeMethod · 0.45

Tested by

no test coverage detected