diff --git a/swh/storage/tests/storage_testing.py b/swh/storage/tests/storage_testing.py --- a/swh/storage/tests/storage_testing.py +++ b/swh/storage/tests/storage_testing.py @@ -56,3 +56,22 @@ def tearDown(self): self.objtmp.cleanup() super().tearDown() + + def reset_tables(self): + db = self.test_db[self.TEST_STORAGE_DB_NAME] + conn = db.conn + cursor = db.cursor + + cursor.execute("""SELECT table_name FROM information_schema.tables + WHERE table_schema = %s""", ('public',)) + + tables = set(table for (table,) in cursor.fetchall()) + tables -= {'dbversion', 'entity', 'entity_history', 'listable_entity', + 'fossology_license', 'indexer_configuration'} + + for table in tables: + cursor.execute('truncate table %s cascade' % table) + + cursor.execute('delete from entity where generated=true') + cursor.execute('delete from entity_history where generated=true') + conn.commit() diff --git a/swh/storage/tests/test_storage.py b/swh/storage/tests/test_storage.py --- a/swh/storage/tests/test_storage.py +++ b/swh/storage/tests/test_storage.py @@ -545,20 +545,7 @@ } def tearDown(self): - self.cursor.execute("""SELECT table_name FROM information_schema.tables - WHERE table_schema = %s""", ('public',)) - - tables = set(table for (table,) in self.cursor.fetchall()) - tables -= {'dbversion', 'entity', 'entity_history', 'listable_entity', - 'fossology_license', 'indexer_configuration'} - - for table in tables: - self.cursor.execute('truncate table %s cascade' % table) - - self.cursor.execute('delete from entity where generated=true') - self.cursor.execute('delete from entity_history where generated=true') - self.conn.commit() - + self.reset_tables() super().tearDown() def fetch_tools(self):