Python django.test.utils.get_runner() Examples

The following are 30 code examples of django.test.utils.get_runner(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.test.utils , or try the search function .
Example #1
Source File: setup_tests.py    From djongo with GNU Affero General Public License v3.0 6 votes vote down vote up
def make_test_runner(verbosity, interactive, failfast, keepdb, reverse,
                     debug_sql, parallel, tags, exclude_tags):
    if not hasattr(settings, 'TEST_RUNNER'):
        settings.TEST_RUNNER = 'django.test.runner.DiscoverRunner'
    TestRunner = get_runner(settings)

    test_runner = TestRunner(
        verbosity=verbosity,
        interactive=interactive,
        failfast=failfast,
        keepdb=keepdb,
        reverse=reverse,
        debug_sql=debug_sql,
        parallel=actual_test_processes(parallel),
        tags=tags,
        exclude_tags=exclude_tags,
    )
    return test_runner 
Example #2
Source File: runtests.py    From drf-to-s3 with MIT License 6 votes vote down vote up
def main():
    TestRunner = get_runner(settings)

    test_runner = TestRunner()
    if len(sys.argv) == 2:
        test_case = sys.argv[1]
    elif len(sys.argv) == 1:
        test_case = 'tests'
    else:
        print(usage())
        sys.exit(1)
    test_module_name = 'drf_to_s3.'
    if django.VERSION[0] == 1 and django.VERSION[1] < 6:
        test_module_name = ''

    failures = test_runner.run_tests([test_module_name + test_case])

    sys.exit(failures) 
Example #3
Source File: run_tests.py    From django-websocket-request with MIT License 6 votes vote down vote up
def main():
    settings.configure(
        ROOT_URLCONF='wsrequest.tests',
        INSTALLED_APPS=[
            'django.contrib.auth',
            'django.contrib.contenttypes',
            'django.contrib.sessions',
        ],
        DATABASES={
            'default': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME':  'db.sqlite3',
            }
        }
    )

    from django.test.utils import get_runner

    test_runner = get_runner(settings)(verbosity=1, interactive=True)

    failures = test_runner.run_tests(['wsrequest.tests'])

    sys.exit(failures) 
Example #4
Source File: runtests.py    From pwned-passwords-django with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def run_tests():
    # Making Django run this way is a two-step process. First, call
    # settings.configure() to give Django settings to work with:
    from django.conf import settings

    settings.configure(**SETTINGS_DICT)

    # Then, call django.setup() to initialize the application registry
    # and other bits:
    import django

    django.setup()

    # Now we instantiate a test runner...
    from django.test.utils import get_runner

    TestRunner = get_runner(settings)

    # And then we run tests and return the results.
    test_runner = TestRunner(verbosity=2, interactive=True)
    failures = test_runner.run_tests(["tests"])
    sys.exit(failures) 
Example #5
Source File: runtests.py    From django-rest-framework-expiring-tokens with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def run():
    """Run tests with Django setup."""
    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    from django.conf import settings

    # Will only work in 1.7
    try:
        from django import setup
    except ImportError:
        pass
    else:
        setup()

    from django.test.utils import get_runner

    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(["tests"])
    sys.exit(bool(failures)) 
Example #6
Source File: runtests.py    From django-subscriptions with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def run_tests():
    # First configure settings, then call django.setup() to initialise
    from django.conf import settings

    settings.configure(**SETTINGS_DICT)
    import django

    django.setup()

    # Now create the test runner
    from django.test.utils import get_runner

    TestRunner = get_runner(settings)

    # And then we run tests and return the results.
    test_runner = TestRunner(verbosity=2, interactive=True)
    failures = test_runner.run_tests(["tests"])
    sys.exit(failures) 
Example #7
Source File: runtests.py    From django-rest-framework-docs with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def run_tests_coverage():
    if __name__ == "__main__":
        os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
        django.setup()
        TestRunner = get_runner(settings)
        test_runner = TestRunner()

        # Setup Coverage
        cov = coverage(source=["rest_framework_docs"], omit=["rest_framework_docs/__init__.py"])
        cov.start()

        failures = test_runner.run_tests(["tests"])

        if bool(failures):
            cov.erase()
            sys.exit("Tests Failed. Coverage Cancelled.")

        # If success show coverage results
        cov.stop()
        cov.save()
        cov.report()
        cov.html_report(directory='covhtml') 
Example #8
Source File: setup.py    From django-cryptography with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def run_tests(self):
        import django
        django.setup()

        from django.conf import settings
        from django.test.utils import get_runner

        TestRunner = get_runner(settings, self.testrunner)

        test_runner = TestRunner(
            pattern=self.pattern,
            top_level=self.top_level_directory,
            verbosity=self.verbose,
            interactive=(not self.noinput),
            failfast=self.failfast,
            keepdb=self.keepdb,
            reverse=self.reverse,
            debug_sql=self.debug_sql,
            output_dir=self.output_dir)
        failures = test_runner.run_tests(self.test_labels)

        sys.exit(bool(failures)) 
Example #9
Source File: runtests.py    From django-taxii-services with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def runtests():
    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_settings'
    django.setup()

    TestRunner = get_runner(settings)
    test_runner = TestRunner()

    # By default, run all of the tests
    tests = ['tests']

    # Allow running a subset of tests via the command line.
    if len(sys.argv) > 1:
        tests = sys.argv[1:]

    failures = test_runner.run_tests(tests, verbosity=3)
    if failures:
        sys.exit(failures) 
Example #10
Source File: runtests.py    From luscan-devel with GNU General Public License v2.0 6 votes vote down vote up
def runtests():
    """
    The test runner for setup.py test usage. This sets up
    a memory database with sqlite3 and runs the tests via
    the django test command.
    """
    from conf import settings
    settings = settings(
        DATABASE_ENGINE='sqlite3',
        DATABASE_NAME=':memory:',
    )

    from django.test.utils import get_runner
    test_runner = get_runner(settings)
    failures = test_runner([], verbosity=1, interactive=True)
    raise SystemExit(failures) 
Example #11
Source File: test.py    From luscan-devel with GNU General Public License v2.0 6 votes vote down vote up
def handle(self, *test_labels, **options):
        from django.conf import settings
        from django.test.utils import get_runner

        TestRunner = get_runner(settings, options.get('testrunner'))
        options['verbosity'] = int(options.get('verbosity'))

        if options.get('liveserver') is not None:
            os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = options['liveserver']
            del options['liveserver']

        test_runner = TestRunner(**options)
        failures = test_runner.run_tests(test_labels)

        if failures:
            sys.exit(bool(failures)) 
Example #12
Source File: runtests.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def runDjangoTest():
    cleanMedia()
    verbosity = 1
    if "-v" in sys.argv or "--verbose" in sys.argv:
        verbosity = 2
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner(top_level="ls/joyous",
                             verbosity=verbosity,
                             keepdb=True)
    labels = ["ls.joyous.tests."+arg for arg in sys.argv[1:]
              if not arg.startswith("-")]
    if not labels:
        labels = ["ls.joyous.tests"]
    failures = test_runner.run_tests(labels)
    return failures 
Example #13
Source File: runtests.py    From django-unsubscribe with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def main():
    try:
        django.setup()
    except AttributeError:
        pass
    TestRunner = get_runner(settings)
    test_runner = TestRunner()

    if len(sys.argv) == 2:
        test_case = '.' + sys.argv[1]
    elif len(sys.argv) == 1:
        test_case = ''
    else:
        print(usage())
        sys.exit(1)

    test_module_name = 'unsubscribe.tests'

    if django.VERSION[0] == 1 and django.VERSION[1] < 6:
        test_module_name = 'tests'

    failures = test_runner.run_tests(
        [test_module_name + test_case], verbosity=1, interactive=True)

    sys.exit(failures) 
Example #14
Source File: runtests.py    From django-celerybeat-status with MIT License 6 votes vote down vote up
def run_tests(*args, **kwargs):
    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner(**kwargs)
    failures = test_runner.run_tests(args)
    try:
        os.remove('./celerybeat-schedule.bak')
    except Exception:
        pass

    try:
        os.remove('./celerybeat-schedule.dat')
    except Exception:
        pass

    try:
        os.remove('./celerybeat-schedule.dir')
    except Exception:
        pass
        
    sys.exit(bool(failures)) 
Example #15
Source File: runtests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def django_tests(verbosity, interactive, failfast, keepdb, reverse,
                 test_labels, debug_sql, parallel, tags, exclude_tags):
    print(verbosity, interactive, failfast, keepdb, reverse,
                 test_labels, debug_sql, parallel, tags, exclude_tags)
    state = setup(verbosity, test_labels, parallel)
    extra_tests = []

    # Run the test suite, including the extra validation tests.
    sys.path.insert(0, '/home/esidsen/projects/djongo/tests/django_tests/test_utils')
    if not hasattr(settings, 'TEST_RUNNER'):
        settings.TEST_RUNNER = 'django.test.runner.DiscoverRunner'
    settings.TEST_RUNNER = 'test_runner.DiscoverRunner'
    TestRunner = get_runner(settings)
    print(TestRunner)

    test_runner = TestRunner(
        verbosity=verbosity,
        interactive=interactive,
        failfast=failfast,
        keepdb=keepdb,
        reverse=reverse,
        debug_sql=debug_sql,
        parallel=actual_test_processes(parallel),
        tags=tags,
        exclude_tags=exclude_tags,
    )
    failures = test_runner.run_tests(
        test_labels or get_installed(),
        extra_tests=extra_tests,
    )
    teardown(state)
    return failures 
Example #16
Source File: runtests.py    From django-treenode with MIT License 5 votes vote down vote up
def runtests():
    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(['tests'])
    sys.exit(bool(failures)) 
Example #17
Source File: runtests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def django_tests(verbosity, interactive, failfast, keepdb, reverse,
                 test_labels, debug_sql, parallel, tags, exclude_tags):
    state = setup(verbosity, test_labels, parallel)
    extra_tests = []

    # Run the test suite, including the extra validation tests.
    if not hasattr(settings, 'TEST_RUNNER'):
        settings.TEST_RUNNER = 'django.test.runner.DiscoverRunner'
    TestRunner = get_runner(settings)

    test_runner = TestRunner(
        verbosity=verbosity,
        interactive=interactive,
        failfast=failfast,
        keepdb=keepdb,
        reverse=reverse,
        debug_sql=debug_sql,
        parallel=actual_test_processes(parallel),
        tags=tags,
        exclude_tags=exclude_tags,
    )
    failures = test_runner.run_tests(
        test_labels or get_installed(),
        extra_tests=extra_tests,
    )
    teardown(state)
    return failures 
Example #18
Source File: runtests.py    From django-sqlserver with MIT License 5 votes vote down vote up
def django_tests(verbosity, interactive, failfast, keepdb, reverse,
                 test_labels, debug_sql, parallel, tags, exclude_tags):
    state = setup(verbosity, test_labels, parallel)
    extra_tests = []

    # Run the test suite, including the extra validation tests.
    if not hasattr(settings, 'TEST_RUNNER'):
        settings.TEST_RUNNER = 'django.test.runner.DiscoverRunner'
    TestRunner = get_runner(settings)

    test_runner = TestRunner(
        verbosity=verbosity,
        interactive=interactive,
        failfast=failfast,
        keepdb=keepdb,
        reverse=reverse,
        debug_sql=debug_sql,
        parallel=actual_test_processes(parallel),
        tags=tags,
        exclude_tags=exclude_tags,
    )
    failures = test_runner.run_tests(
        test_labels or get_installed(),
        extra_tests=extra_tests,
    )
    teardown(state)
    return failures 
Example #19
Source File: runtests.py    From django-admin-easy with MIT License 5 votes vote down vote up
def runtests():
    os.environ['DJANGO_SETTINGS_MODULE'] = 'test_project.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(["tests"])
    sys.exit(bool(failures)) 
Example #20
Source File: runtests.py    From django-grpc with MIT License 5 votes vote down vote up
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures)) 
Example #21
Source File: runtests.py    From django-telegrambot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    # Run tests
    TestRunner = get_runner(settings)
    test_runner = TestRunner()

    failures = test_runner.run_tests(test_args)

    if failures:
        sys.exit(bool(failures)) 
Example #22
Source File: runtests.py    From django-rest-auth with MIT License 5 votes vote down vote up
def runtests():
    TestRunner = get_runner(settings)
    test_runner = TestRunner(verbosity=1, interactive=True)
    if hasattr(django, 'setup'):
        django.setup()
    failures = test_runner.run_tests(['rest_auth'])
    sys.exit(bool(failures)) 
Example #23
Source File: runtests.py    From drf-dynamic-fields with MIT License 5 votes vote down vote up
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    test_runner = get_runner(settings)()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures)) 
Example #24
Source File: runtests.py    From django-field-history with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    # Run tests
    TestRunner = get_runner(settings)
    test_runner = TestRunner()

    failures = test_runner.run_tests(test_args)

    if failures:
        sys.exit(bool(failures)) 
Example #25
Source File: runtests.py    From django-content-gallery with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def runtests():
    django.setup()
    TestRunner = get_runner(settings)
    runner = TestRunner(verbosity=1, interactive=True)
    failures = runner.run_tests(['content_gallery'])
    sys.exit(failures) 
Example #26
Source File: runtests.py    From djangocms-spa with MIT License 5 votes vote down vote up
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures)) 
Example #27
Source File: runtests.py    From django-translation-manager with Mozilla Public License 2.0 5 votes vote down vote up
def run_tests():
    import django
    from django.test.utils import get_runner
    from django.conf import settings

    django.setup()
    test_runner = get_runner(settings)()
    failures = test_runner.run_tests(["tests"])
    sys.exit(bool(failures)) 
Example #28
Source File: runtests.py    From Simple-Q-A-App-using-Python-Django with MIT License 5 votes vote down vote up
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures)) 
Example #29
Source File: runtests.py    From celery-monitor with GNU General Public License v3.0 5 votes vote down vote up
def runtests():
    TestRunner = get_runner(settings)
    test_runner = TestRunner(verbosity=1, interactive=True)
    if hasattr(django, 'setup'):
        django.setup()
    failures = test_runner.run_tests(['django_admin'])
    sys.exit(bool(failures)) 
Example #30
Source File: test.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def create_parser(self, prog_name, subcommand):
        test_runner_class = get_runner(settings, self.test_runner)
        options = self.option_list + getattr(
            test_runner_class, 'option_list', ())
        return OptionParser(prog=prog_name,
                            usage=self.usage(subcommand),
                            version=self.get_version(),
                            option_list=options)