#!/usr/bin/python import unittest from django.test.simple import DjangoTestSuiteRunner class MegaTestSuiteRunner(DjangoTestSuiteRunner): """ works like standart django test suite runner. Addition: Testcases with true EXISTING_DB attr run on working database. All other testcases executed standartly (on test_xxx database). Usage: 1) write in settings.py: TEST_RUNNER = 'DjHDGutils.megatestrunner.MegaTestSuiteRunner' 2) add property to testcases desired to run on working db: EXISTING_DB = True """ def run_tests(self, test_labels, extra_tests=None): """ divide tests suite and run separately """ self.setup_test_environment() suite_all = self.build_suite(test_labels, extra_tests) suite = unittest.TestSuite() suite_existing_db = unittest.TestSuite() # divide tests for t in suite_all._tests: if getattr(t, 'EXISTING_DB', False): suite_existing_db.addTest(t) else: suite.addTest(t) result = 0 if len(suite._tests) > 0: print 'Standard testing:' old_names = self.setup_databases() run_result = self.run_suite(suite) result += self.suite_result(suite, run_result) self.teardown_databases(old_names) if len(suite_existing_db._tests) > 0: print 'Existing db testing:' run_result = self.run_suite(suite_existing_db) result += self.suite_result(suite_existing_db, run_result) self.teardown_test_environment() return result