]> err.no Git - dak/commitdiff
Optimize performance of running multiple DB tests.
authorTorsten Werner <twerner@debian.org>
Sun, 16 Jan 2011 23:34:36 +0000 (00:34 +0100)
committerTorsten Werner <twerner@debian.org>
Sun, 16 Jan 2011 23:34:36 +0000 (00:34 +0100)
Signed-off-by: Torsten Werner <twerner@debian.org>
tests/db_test.py

index d7f906cd34a147ad79916b283c0122be0761e34a..4f01f6d5d1583a89128a4b12c1fd41c9546fd88e 100644 (file)
@@ -39,7 +39,9 @@ class DBDakTestCase(DakTestCase):
         for table in all_tables:
             self.execute(create_trigger % (table, table))
 
-    def setUp(self):
+    metadata = None
+
+    def initialize(self):
         cnf = Config()
         if cnf["DB::Name"] in ('backports', 'obscurity', 'projectb'):
             self.fail("You have configured an invalid database name: '%s'." % \
@@ -58,12 +60,16 @@ class DBDakTestCase(DakTestCase):
 
         pickle_filename = 'db-metadata-%s.pkl' % __version__
         pickle_file = open(fixture(pickle_filename), 'r')
-        self.metadata = pickle.load(pickle_file)
+        DBDakTestCase.metadata = pickle.load(pickle_file)
         self.metadata.ddl_listeners = pickle.load(pickle_file)
         pickle_file.close()
         self.metadata.bind = create_engine(connstr)
         self.metadata.create_all()
         self.create_all_triggers()
+
+    def setUp(self):
+        if self.metadata is None:
+            self.initialize()
         self.session = DBConn().session()
 
     def classes_to_clean(self):
@@ -79,5 +85,6 @@ class DBDakTestCase(DakTestCase):
         for class_ in self.classes_to_clean():
             self.session.query(class_).delete()
         self.session.commit()
+        # usually there is no need to drop all tables here
         #self.metadata.drop_all()