def _fixture_teardown(cls): """Empty (only) the tables we loaded fixtures into, then commit.""" if hasattr(cls, "fixtures") and cls.fixtures and getattr(cls, "_fb_should_teardown_fixtures", True): # If the fixture-bundling test runner advises us that the next test # suite is going to reuse these fixtures, don't tear them down. for db in cls._databases(): tables = tables_used_by_fixtures(cls.fixtures, using=db) # TODO: Think about respecting _meta.db_tablespace, not just # db_table. if tables: connection = connections[db] cursor = connection.cursor() # TODO: Rather than assuming that anything added to by a # fixture can be emptied, remove only what the fixture # added. This would probably solve input.mozilla.com's # failures (since worked around) with Site objects; they # were loading additional Sites with a fixture, and then # the Django-provided example.com site was evaporating. if uses_mysql(connection): cursor.execute("SET FOREIGN_KEY_CHECKS=0") for table in tables: # Truncate implicitly commits. cursor.execute("TRUNCATE `%s`" % table) # TODO: necessary? cursor.execute("SET FOREIGN_KEY_CHECKS=1") else: for table in tables: cursor.execute("DELETE FROM %s" % table) transaction.commit(using=db)
def _fixture_teardown(self): """Executes a quick truncation of MySQL tables.""" cursor = connection.cursor() using_mysql = uses_mysql(connection) if using_mysql: cursor.execute("SET FOREIGN_KEY_CHECKS=0") table = connection.introspection.django_table_names() for table in set(table) - TEST_UTILS_NO_TRUNCATE: if using_mysql: cursor.execute("TRUNCATE `%s`" % table) else: cursor.execute("DELETE FROM %s" % table) cursor.close()