我们从Python开源项目中,提取了以下15个代码示例,用于说明如何使用django.test.runner.DiscoverRunner()。
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()
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)
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'
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)
def setUpClass(cls): django.setup() cls.runner = DiscoverRunner() cls.runner.setup_test_environment() cls.old_config = cls.runner.setup_databases()
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)
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, })
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()
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()
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()
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()
def before_all(context): django.setup() context.test_runner = DiscoverRunner() context.test_runner.setup_test_environment() context.browser = Browser('phantomjs')
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