Python django.test.runner 模块,DiscoverRunner() 实例源码

我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用django.test.runner.DiscoverRunner()

项目:elasticsearch2-haystack    作者:NDevox    | 项目源码 | 文件源码
def setup():
    try:
        from elasticsearch import Elasticsearch, ElasticsearchException
    except ImportError:
        raise unittest.SkipTest("elasticsearch-py not installed.")

    es = Elasticsearch(settings.HAYSTACK_CONNECTIONS['elasticsearch']['URL'])
    try:
        es.info()
    except ElasticsearchException as e:
        raise unittest.SkipTest("elasticsearch not running on %r" % settings.HAYSTACK_CONNECTIONS['elasticsearch']['URL'], e)

    global test_runner
    global old_config

    from django.test.runner import DiscoverRunner

    test_runner = DiscoverRunner()
    test_runner.setup_test_environment()
    old_config = test_runner.setup_databases()
项目:django-social-api    作者:ramusus    | 项目源码 | 文件源码
def _tests_1_8(self):
        """
        Fire up the Django test suite developed for version 1.8 and up
        """
        test_settings = self.custom_settings
        installed_apps = test_settings.pop('INSTALLED_APPS', ())
        settings.configure(
            DEBUG=True,
            DATABASES=self.get_database(1.8),
            MIDDLEWARE_CLASSES=('django.middleware.common.CommonMiddleware',
                                'django.middleware.csrf.CsrfViewMiddleware'),
            INSTALLED_APPS=tuple(self.INSTALLED_APPS + installed_apps + self.apps),
            **test_settings
        )
        from django.test.runner import DiscoverRunner
        import django
        django.setup()
        failures = DiscoverRunner().run_tests(self.apps, verbosity=1)
        if failures:
            sys.exit(failures)
项目:kmanga    作者:aplanas    | 项目源码 | 文件源码
def setUp(self):
        self.dr = DiscoverRunner()
        self.old_config = self.dr.setup_databases()

        self.updatedb = UpdateDBPipeline(
            images_store='tests/fixtures/images')
        source = Source.objects.create(
            name='source',
            spider='spider',
            url='http://example.com'
        )
        SourceLanguage.objects.create(
            language='EN',
            source=source
        )
        self.spider = Spider()
        self.spider.name = 'Spider'
项目:django-model-changes-py3    作者:iansprice    | 项目源码 | 文件源码
def runtests(*test_args, **kwargs):
    django_setup()
    if not test_args:
        test_args = ['tests']
    parent = dirname(abspath(__file__))
    sys.path.insert(0, parent)
    test_runner = DiscoverRunner(
        verbosity=kwargs.get('verbosity', 1),
        interactive=kwargs.get('interactive', False),
        failfast=kwargs.get('failfast')
    )
    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
项目:deb-python-oauth2client    作者:openstack    | 项目源码 | 文件源码
def setUpClass(cls):
        django.setup()
        cls.runner = DiscoverRunner()
        cls.runner.setup_test_environment()
        cls.old_config = cls.runner.setup_databases()
项目:REMAP    作者:REMAPApp    | 项目源码 | 文件源码
def setUpClass(cls):
        django.setup()
        cls.runner = DiscoverRunner()
        cls.runner.setup_test_environment()
        cls.old_config = cls.runner.setup_databases()
项目:django-partial-index    作者:mattiaslinnap    | 项目源码 | 文件源码
def main(args):
    # Since this test suite is designed to be ran outside of ./manage.py test, we need to do some setup first.
    import django
    from django.conf import settings
    settings.configure(INSTALLED_APPS=['testapp'], DATABASES=DATABASES_FOR_DB[args.db])
    django.setup()

    from django.test.runner import DiscoverRunner
    test_runner = DiscoverRunner(top_level=TESTS_DIR, interactive=False, keepdb=False)
    failures = test_runner.run_tests(['tests'])
    if failures:
        sys.exit(1)
项目:deb-python-semantic-version    作者:openstack    | 项目源码 | 文件源码
def setUpModule():
    if not django_loaded:  # pragma: no cover
        raise unittest.SkipTest("Django not installed")
    django_test_utils.setup_test_environment()
    runner = django_test_runner.DiscoverRunner()
    runner_state = runner.setup_databases()
    test_state.update({
        'runner': runner,
        'runner_state': runner_state,
    })
项目:django-chemtrails    作者:inonit    | 项目源码 | 文件源码
def setup():
    from django.test.runner import DiscoverRunner
    global test_runner
    global old_config

    test_runner = DiscoverRunner()
    test_runner.setup_test_environment()
    old_config = test_runner.setup_databases()
项目:django-hesab    作者:rhblind    | 项目源码 | 文件源码
def setup():
    global test_runner
    global old_config

    try:
        from django.test.simple import DjangoTestSuiteRunner as TestSuiteRunner
    except ImportError:
        # DjangoTestSuiteRunner was deprecated in django 1.8:
        # https://docs.djangoproject.com/en/1.8/internals/deprecation/#deprecation-removed-in-1-8
        from django.test.runner import DiscoverRunner as TestSuiteRunner

    test_runner = TestSuiteRunner()
    test_runner.setup_test_environment()
    old_config = test_runner.setup_databases()
项目:django-haystack-elasticsearch    作者:CraveFood    | 项目源码 | 文件源码
def setup():
    global test_runner
    global old_config

    from django.test.runner import DiscoverRunner

    test_runner = DiscoverRunner()
    test_runner.setup_test_environment()
    old_config = test_runner.setup_databases()
项目:py2swagger    作者:Arello-Mobile    | 项目源码 | 文件源码
def setup():
    global test_runner
    global old_config

    try:
        # DjangoTestSuiteRunner was deprecated in django 1.8:
        # https://docs.djangoproject.com/en/1.8/internals/deprecation/#deprecation-removed-in-1-8
        from django.test.runner import DiscoverRunner as TestSuiteRunner
    except ImportError:
        from django.test.simple import DjangoTestSuiteRunner as TestSuiteRunner

    test_runner = TestSuiteRunner()
    test_runner.setup_test_environment()
    test_runner.setup_databases()
项目:CRM_JointProject    作者:rarques    | 项目源码 | 文件源码
def before_all(context):
    django.setup()
    context.test_runner = DiscoverRunner()
    context.test_runner.setup_test_environment()
    context.browser = Browser('phantomjs')
项目:django-test-query-counter    作者:sophilabs    | 项目源码 | 文件源码
def setUp(self):
        # Simple class that doesn't output to the standard output
        class StringIOTextRunner(TextTestRunner):
            def __init__(self, *args, **kwargs):
                kwargs['stream'] = StringIO()
                super().__init__(*args, **kwargs)

        self.test_runner = DiscoverRunner()
        self.test_runner.test_runner = StringIOTextRunner
项目:django-test-query-counter    作者:sophilabs    | 项目源码 | 文件源码
def setUp(self):
        # Simple class that doesn't output to the standard output
        class StringIOTextRunner(TextTestRunner):
            def __init__(self, *args, **kwargs):
                kwargs['stream'] = StringIO()
                super().__init__(*args, **kwargs)

        self.test_runner = DiscoverRunner()
        self.test_runner.test_runner = StringIOTextRunner