MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / provide_metadata

Function provide_metadata

lib/sqlalchemy/testing/util.py:236–276  ·  view source on GitHub ↗

Provide bound MetaData for a single test, dropping afterwards. Legacy; use the "metadata" pytest fixture.

(fn, *args, **kw)

Source from the content-addressed store, hash-verified

234
235@decorator
236def provide_metadata(fn, *args, **kw):
237 """Provide bound MetaData for a single test, dropping afterwards.
238
239 Legacy; use the "metadata" pytest fixture.
240
241 """
242
243 from . import fixtures
244
245 metadata = schema.MetaData()
246 self = args[0]
247 prev_meta = getattr(self, "metadata", None)
248 self.metadata = metadata
249 try:
250 return fn(*args, **kw)
251 finally:
252 # close out some things that get in the way of dropping tables.
253 # when using the "metadata" fixture, there is a set ordering
254 # of things that makes sure things are cleaned up in order, however
255 # the simple "decorator" nature of this legacy function means
256 # we have to hardcode some of that cleanup ahead of time.
257
258 # close ORM sessions
259 fixtures.close_all_sessions()
260
261 # integrate with the "connection" fixture as there are many
262 # tests where it is used along with provide_metadata
263 cfc = fixtures.base._connection_fixture_connection
264 if cfc:
265 # TODO: this warning can be used to find all the places
266 # this is used with connection fixture
267 # warn("mixing legacy provide metadata with connection fixture")
268 drop_all_tables_from_metadata(metadata, cfc)
269 # as the provide_metadata fixture is often used with "testing.db",
270 # when we do the drop we have to commit the transaction so that
271 # the DB is actually updated as the CREATE would have been
272 # committed
273 cfc.get_transaction().commit()
274 else:
275 drop_all_tables_from_metadata(metadata, config.db)
276 self.metadata = prev_meta
277
278
279def flag_combinations(*combinations):

Callers

nothing calls this directly

Calls 3

commitMethod · 0.45
get_transactionMethod · 0.45

Tested by

no test coverage detected