Provide bound MetaData for a single test, dropping afterwards. Legacy; use the "metadata" pytest fixture.
(fn, *args, **kw)
| 193 | |
| 194 | @decorator |
| 195 | def provide_metadata(fn, *args, **kw): |
| 196 | """Provide bound MetaData for a single test, dropping afterwards. |
| 197 | |
| 198 | Legacy; use the "metadata" pytest fixture. |
| 199 | |
| 200 | """ |
| 201 | |
| 202 | from . import fixtures |
| 203 | |
| 204 | metadata = schema.MetaData() |
| 205 | self = args[0] |
| 206 | prev_meta = getattr(self, "metadata", None) |
| 207 | self.metadata = metadata |
| 208 | try: |
| 209 | return fn(*args, **kw) |
| 210 | finally: |
| 211 | # close out some things that get in the way of dropping tables. |
| 212 | # when using the "metadata" fixture, there is a set ordering |
| 213 | # of things that makes sure things are cleaned up in order, however |
| 214 | # the simple "decorator" nature of this legacy function means |
| 215 | # we have to hardcode some of that cleanup ahead of time. |
| 216 | |
| 217 | # close ORM sessions |
| 218 | fixtures.close_all_sessions() |
| 219 | |
| 220 | # integrate with the "connection" fixture as there are many |
| 221 | # tests where it is used along with provide_metadata |
| 222 | cfc = fixtures.base._connection_fixture_connection |
| 223 | if cfc: |
| 224 | # TODO: this warning can be used to find all the places |
| 225 | # this is used with connection fixture |
| 226 | # warn("mixing legacy provide metadata with connection fixture") |
| 227 | drop_all_tables_from_metadata(metadata, cfc) |
| 228 | # as the provide_metadata fixture is often used with "testing.db", |
| 229 | # when we do the drop we have to commit the transaction so that |
| 230 | # the DB is actually updated as the CREATE would have been |
| 231 | # committed |
| 232 | cfc.get_transaction().commit() |
| 233 | else: |
| 234 | drop_all_tables_from_metadata(metadata, config.db) |
| 235 | self.metadata = prev_meta |
| 236 | |
| 237 | |
| 238 | def flag_combinations(*combinations): |
nothing calls this directly
no test coverage detected