Exemple #1
0
    def run_suite(self, suite, **kwargs):
        runner = unittest.TextTestRunner(verbosity=self.verbosity,
                                         failfast=self.failfast).run

        profile.runctx('result = run_tests(suite)', {
            'run_tests': runner,
            'suite': suite,
        }, locals(), getattr(settings, 'TEST_PROFILE', None))
        return locals()['result']
    def run_suite(self, suite, **kwargs):
        if self.jenkins:
            for task in self.tasks:
                if hasattr(task, 'before_suite_run'):
                    task.before_suite_run(suite, **kwargs)

            # Use the XMLTestResult so that results can be saved as XML
            result = unittest.TextTestRunner(
                buffer=True,
                resultclass=XMLTestResult,
                verbosity=self.verbosity,
                failfast=self.failfast,
            ).run(suite)

            # Dump the results to an XML file
            result.dump_xml(self.output_dir)

            for task in self.tasks:
                if hasattr(task, 'after_suite_run'):
                    task.after_suite_run(suite, **kwargs)

            return result
        # If Jenkins is not enabled, just run the suite as normal
        return super(CIRunner, self).run_suite(suite, **kwargs)
 def run_suite(self, suite, **kwargs):
     return unittest.TextTestRunner(verbosity=self.verbosity,
                                    failfast=self.failfast,
                                    stream=sys.stderr).run(suite)
Exemple #4
0
 def test_normalizer(self):
     suite = make_doctest("test_utils.doctest_output")
     failures = unittest.TextTestRunner(stream=six.StringIO()).run(suite)
     self.assertEqual(failures.failures, [])
def run(verbosity=2):
    unittest.TextTestRunner(verbosity=verbosity).run(suite())
Exemple #6
0
 def run_suite(self, suite, **kwargs):
     return unittest.TextTestRunner(verbosity=self.verbosity, 
                            failfast=self.failfast) \
         .run(suite)
Exemple #7
0
#!/usr/bin/env python
import os
import sys

import django
from django.test.utils import setup_test_environment
from django.utils import unittest

os.environ['DJANGO_SETTINGS_MODULE'] = 'WhatManager2.settings'

if __name__ == '__main__':
    setup_test_environment()
    django.setup()

    suite = unittest.TestLoader().discover('integration_tests')
    result = unittest.TextTestRunner(verbosity=2).run(suite)
    sys.exit(not result.wasSuccessful())
def run_tests(test_labels, verbosity=1, interactive=True, extra_tests=[]):
    """
    worsk exactly as per normal test
    but only creates the test_db if it doesn't yet exist
    and does not destroy it when done
    tables are flushed and fixtures loaded between tests as per usual
    but if your schema has not changed then this saves significant amounts of time
    and speeds up the test cycle

    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 = apps.get_app(label)
                suite.addTest(build_suite(app))
    else:
        for app in apps.get_apps():
            suite.addTest(build_suite(app))

    for test in extra_tests:
        suite.addTest(test)

    suite = reorder_suite(suite, (TestCase, ))

    old_name = settings.DATABASES['default']['NAME']

    # Everything up to here is from django.test.simple

    from django.db.backends import creation
    from django.db import connection, DatabaseError

    if settings.DATABASES['default']['TEST_NAME']:
        settings.DATABASES['default']['NAME'] = settings.DATABASES['default'][
            'TEST_NAME']
    else:
        settings.DATABASES['default'][
            'NAME'] = creation.TEST_DATABASE_PREFIX + settings.DATABASES[
                'default']['NAME']
    connection.settings_dict["DATABASE_NAME"] = settings.DATABASES['default'][
        'NAME']

    # does test db exist already ?
    try:
        if settings.DATABASES['default']['ENGINE'] == 'sqlite3':
            if not os.path.exists(settings.DATABASES['default']['NAME']):
                raise DatabaseError
        cursor = connection.cursor()
    except Exception:
        # db does not exist
        # juggling !  create_test_db switches the DATABASE_NAME to the TEST_DATABASE_NAME
        settings.DATABASES['default']['NAME'] = old_name
        connection.settings_dict["DATABASE_NAME"] = old_name
        connection.creation.create_test_db(verbosity, autoclobber=True)
    else:
        connection.close()

    settings.DATABASES['default'][
        'SUPPORTS_TRANSACTIONS'] = connections_support_transactions()

    result = unittest.TextTestRunner(verbosity=verbosity).run(suite)

    # Since we don't call destory_test_db, we need to set the db name back.
    settings.DATABASES['default']['NAME'] = old_name
    connection.settings_dict["DATABASE_NAME"] = old_name
    teardown_test_environment()

    return len(result.failures) + len(result.errors)
Exemple #9
0
 def handle_noargs(self, **options):
     suite = unittest.TestLoader().loadTestsFromTestCase(AHJUrlsTestCase)
     unittest.TextTestRunner().run(suite)