"""Utilities related to nose."""fromdjango.core.managementimportcall_commandfromdjango.dbimportDEFAULT_DB_ALIAS,connections,transactionimportdjango_noseclassNoseTestSuiteRunner(django_nose.NoseTestSuiteRunner):"""Custom NoseTestSuiteRunner."""defsetup_databases(self):""" Setup databases and then flush to remove data added by migrations. """return_value=super(NoseTestSuiteRunner,self).setup_databases()# Delete all data added by data migrations. Unit tests should setup their own data using factories.call_command('flush',verbosity=0,interactive=False,load_initial_data=False)# Through Django 1.8, auto increment sequences are not reset when calling flush on a SQLite db.# So we do it ourselves.# http://sqlite.org/autoinc.htmlconnection=connections[DEFAULT_DB_ALIAS]ifconnection.vendor=='sqlite'andnotconnection.features.supports_sequence_reset:withtransaction.atomic(using=DEFAULT_DB_ALIAS):cursor=connection.cursor()cursor.execute("delete from sqlite_sequence;")returnreturn_value