From 0bb5a9eab829f9a4cfda3c37cdf2202d84e55f3f Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 1 Oct 2012 01:59:59 -0400 Subject: - fix the fixture here that wasn't creating consistently - rewrite --dropfirst to be more industrial strength, includes views - fix order_by="foreign_key" to maintain the same ordering as metadata.sorted_tables. Not ideal that this was the other way throughout 0.7 but this is still a little-used method, in contrast to metadata.sorted_tables. --- lib/sqlalchemy/testing/plugin/noseplugin.py | 31 ++++++++++++++++++----------- 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'lib/sqlalchemy/testing/plugin') diff --git a/lib/sqlalchemy/testing/plugin/noseplugin.py b/lib/sqlalchemy/testing/plugin/noseplugin.py index cf132198f..1034749e7 100644 --- a/lib/sqlalchemy/testing/plugin/noseplugin.py +++ b/lib/sqlalchemy/testing/plugin/noseplugin.py @@ -148,22 +148,29 @@ def _create_testing_engine(options, file_config): @post def _prep_testing_database(options, file_config): from sqlalchemy.testing import engines - from sqlalchemy import schema + from sqlalchemy import schema, inspect # also create alt schemas etc. here? if options.dropfirst: e = engines.utf8_engine() - existing = e.table_names() - if existing: - print "Dropping existing tables in database: " + db_url - try: - print "Tables: %s" % ', '.join(existing) - except: - pass - print "Abort within 5 seconds..." - time.sleep(5) - md = schema.MetaData(e, reflect=True) - md.drop_all() + inspector = inspect(e) + + for vname in inspector.get_view_names(): + e.execute(schema._DropView(schema.Table(vname, schema.MetaData()))) + + for vname in inspector.get_view_names(schema="test_schema"): + e.execute(schema._DropView( + schema.Table(vname, + schema.MetaData(), schema="test_schema"))) + + for tname in reversed(inspector.get_table_names(order_by="foreign_key")): + e.execute(schema.DropTable(schema.Table(tname, schema.MetaData()))) + + for tname in reversed(inspector.get_table_names( + order_by="foreign_key", schema="test_schema")): + e.execute(schema.DropTable( + schema.Table(tname, schema.MetaData(), schema="test_schema"))) + e.dispose() -- cgit v1.2.1