def run_tests(module_list, verbosity=1, extra_tests=[]): """ Run the unit tests for all the modules in the provided list. This testrunner will search each of the modules in the provided list, looking for doctests and unittests in models.py or tests.py within the module. A list of 'extra' tests may also be provided; these tests will be added to the test suite. Returns the number of tests that failed. """ setup_test_environment() settings.DEBUG = False suite = unittest.TestSuite() for module in module_list: suite.addTest(build_suite(module)) for test in extra_tests: suite.addTest(test) old_name = settings.DATABASE_NAME create_test_db(verbosity) result = unittest.TextTestRunner(verbosity=verbosity).run(suite) destroy_test_db(old_name, verbosity) teardown_test_environment() return len(result.failures) + len(result.errors)
def before_testfile(self): # Those imports must be done **after** setup_environ was called from django.test.utils import setup_test_environment from django.test.utils import create_test_db setup_test_environment() create_test_db(verbosity=0) self.dbname = self.settings.TEST_DATABASE_NAME
def run_tests(module_list=get_apps(), verbosity=1, extra_tests=[]): """ Run the unit tests for all the modules in the provided list. This testrunner will search each of the modules in the provided list, looking for doctests and unittests in models.py or tests.py within the module. A list of 'extra' tests may also be provided; these tests will be added to the test suite. Returns the number of tests that failed. """ setup_test_environment() settings.DEBUG = False suite = unittest.TestSuite() for module in module_list: suite.addTest(build_suite(module)) for test in extra_tests: suite.addTest(test) old_name = settings.DATABASE_NAME create_test_db(verbosity) return suite
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]): """ This is basically a copy of the default django run_tests method, except with the addition of the coverage report as documented at http://siddhi.blogspot.com/2007/04/code-coverage-for-your-django-code.html """ if hasattr(settings, 'TEST_DATABASE_ENGINE'): settings.DATABASE_ENGINE = settings.TEST_DATABASE_ENGINE setup_test_environment() settings.DEBUG = False suite = unittest.TestSuite() if test_labels: for label in test_labels: if '.' in label: suite.addTest(build_test(label)) else: app = get_app(label) suite.addTest(build_suite(app)) else: for app in get_apps(): suite.addTest(build_suite(app)) for test in extra_tests: suite.addTest(test) old_name = settings.DATABASE_NAME create_test_db(verbosity, autoclobber=not interactive) coverage.start() print("Running tests ...") result = unittest.TextTestRunner(verbosity=verbosity).run(suite) print("Done running tests.") coverage.stop() if not os.path.exists(settings.COVERAGE_DIR): os.makedirs(settings.COVERAGE_DIR) modules = [] for module_string in settings.COVERAGE_MODULES: module = __import__(module_string, globals(), locals(), [""]) modules.append(module) f, s, m, mf = coverage.analysis(module) fp = file(os.path.join(settings.COVERAGE_DIR, module_string + ".html"), "wb") coverage_color.colorize_file(f, outstream=fp, not_covered=mf) fp.close() coverage.report(modules) coverage.erase() destroy_test_db(old_name, verbosity) teardown_test_environment() return len(result.failures) + len(result.errors)
def run_tests(test_labels, verbosity = 1, interactive = True, extra_tests=[]): """ This is basically a copy of the default django run_tests method, except with the addition of the coverage report as documented at http://siddhi.blogspot.com/2007/04/code-coverage-for-your-django-code.html """ if hasattr(settings, 'TEST_DATABASE_ENGINE'): settings.DATABASE_ENGINE = settings.TEST_DATABASE_ENGINE setup_test_environment() settings.DEBUG = False suite = unittest.TestSuite() if test_labels: for label in test_labels: if '.' in label: suite.addTest(build_test(label)) else: app = get_app(label) suite.addTest(build_suite(app)) else: for app in get_apps(): suite.addTest(build_suite(app)) for test in extra_tests: suite.addTest(test) old_name = settings.DATABASE_NAME create_test_db(verbosity, autoclobber=not interactive) coverage.start() print "Running tests ..." result = unittest.TextTestRunner(verbosity=verbosity).run(suite) print "Done running tests." coverage.stop() if not os.path.exists(settings.COVERAGE_DIR): os.makedirs(settings.COVERAGE_DIR) modules = [] for module_string in settings.COVERAGE_MODULES: module = __import__(module_string, globals(), locals(), [""]) modules.append(module) f,s,m,mf = coverage.analysis(module) fp = file(os.path.join(settings.COVERAGE_DIR, module_string + ".html"), "wb") coverage_color.colorize_file(f, outstream=fp, not_covered=mf) fp.close() coverage.report(modules) coverage.erase() destroy_test_db(old_name, verbosity) teardown_test_environment() return len(result.failures) + len(result.errors)
def run_tests_until_fail(test_labels, verbosity=1, interactive=True, extra_tests=[]): """ Run the unit tests for all the test labels in the provided list. Labels must be of the form: - app.TestClass.test_method Run a single specific test method - app.TestClass Run all the test methods in a given class - app Search for doctests and unittests in the named application. When looking for tests, the test runner will look in the models and tests modules for the application. A list of 'extra' tests may also be provided; these tests will be added to the test suite. Stops the tests at the first failure and returns 1. If all test pass, returns 0. Also displays only the first failure in the failing test suite. """ setup_test_environment() settings.DEBUG = False suite = TestSuite() if test_labels: for label in test_labels: if '.' in label: suite.addTest(build_test(label)) else: app = get_app(label) suite.addTest(build_suite(app)) else: for app in get_apps(): suite.addTest(build_suite(app)) for test in extra_tests: suite.addTest(test) old_name = settings.DATABASE_NAME create_test_db(verbosity, autoclobber=not interactive) result = FailStopTextTestRunner(verbosity=verbosity).run(suite) destroy_test_db(old_name, verbosity) teardown_test_environment() return len(result.failures) + len(result.errors)
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]): """ Run the unit tests for all the test labels in the provided list. Labels must be of the form: - app.TestClass.test_method Run a single specific test method - app.TestClass Run all the test methods in a given class - app Search for doctests and unittests in the named application. When looking for tests, the test runner will look in the models and tests modules for the application. A list of 'extra' tests may also be provided; these tests will be added to the test suite. Returns the number of tests that failed. """ setup_test_environment() settings.DEBUG = False suite = unittest.TestSuite() if test_labels: for label in test_labels: if '.' in label: suite.addTest(build_test(label)) else: app = get_app(label) suite.addTest(build_suite(app)) else: for app in get_apps(): suite.addTest(build_suite(app)) for test in extra_tests: suite.addTest(test) old_name = settings.DATABASE_NAME create_test_db(verbosity, autoclobber=not interactive) result = unittest.TextTestRunner(verbosity=verbosity).run(suite) destroy_test_db(old_name, verbosity) teardown_test_environment() return len(result.failures) + len(result.errors)
def handle(self, *fixture_labels, **options): from django.core.management import call_command from django.test.utils import create_test_db verbosity = int(options.get('verbosity', 1)) addrport = options.get('addrport') # Create a test database. db_name = create_test_db(verbosity=verbosity) # Import the fixture data into the test database. call_command('loaddata', *fixture_labels, **{'verbosity': verbosity}) # Run the development server. Turn off auto-reloading because it causes # a strange error -- it causes this handle() method to be called # multiple times. shutdown_message = '\nServer stopped.\nNote that the test database, %r, has not been deleted. You can explore it on your own.' % db_name call_command('runserver', addrport=addrport, shutdown_message=shutdown_message, use_reloader=False)
def setUpModule(): """ Called to set up the module by the test runner """ global context, models, adapter context = { 'sys.path': sys.path[:], 'sys.modules': sys.modules.copy(), 'os.environ': os.environ.copy(), } if init_django(): from pyamf.tests.adapters.django_app.adapters import models from pyamf.adapters import _django_db_models_base as adapter setup_test_environment() settings.DATABASE_NAME = create_test_db(0, True)
def setUpModule(): """ Called to set up the module by the test runner """ global context, models, storage, adapter context = { 'sys.path': sys.path[:], 'sys.modules': sys.modules.copy(), 'os.environ': os.environ.copy(), } if init_django(): from django.core.files.storage import FileSystemStorage from pyamf.tests.adapters.django_app.adapters import models from pyamf.adapters import _django_db_models_base as adapter setup_test_environment() settings.DATABASE_NAME = create_test_db(verbosity=0, autoclobber=True) storage = FileSystemStorage(mkdtemp())
def setUpModule(): """ Called to set up the module by the test runner """ if not django: return global context, models, storage context = { 'sys.path': sys.path[:], 'sys.modules': sys.modules.copy(), 'os.environ': os.environ.copy(), } if init_django(): from django.core.files.storage import FileSystemStorage from django_app.adapters import models # noqa setup_test_environment() context['DB_NAME'] = create_test_db(verbosity=0, autoclobber=True) storage = FileSystemStorage(mkdtemp())
def create_spatial_db(test=True, verbosity=1, autoclobber=False): if not test: raise NotImplementedError( 'This uses `create_test_db` from test/utils.py') create_test_db(verbosity, autoclobber)
def create_spatial_db(test=True, verbosity=1, autoclobber=False): if not test: raise NotImplementedError('This uses `create_test_db` from test/utils.py') create_test_db(verbosity, autoclobber)