Add custom tests runner that replaces the custom "runtests"
management command.
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django import apps
|
||||
from django.core import management
|
||||
|
||||
|
||||
class Command(management.BaseCommand):
|
||||
help = 'Run all configured tests for the project.'
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'--nomigrations', action='store_true', dest='nomigrations',
|
||||
default=False,
|
||||
help='Don\'t use migrations when creating the test database.'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'--reverse', action='store_true', dest='reverse', default=False,
|
||||
help='Reverses test cases order.'
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
kwargs = {}
|
||||
if options.get('nomigrations'):
|
||||
kwargs['nomigrations'] = True
|
||||
|
||||
if options.get('reverse'):
|
||||
kwargs['reverse'] = True
|
||||
|
||||
test_apps = [app.name for app in apps.apps.get_app_configs() if getattr(app, 'test', False)]
|
||||
|
||||
print 'Testing: {}'.format(', '.join(test_apps))
|
||||
|
||||
management.call_command('test', *test_apps, interactive=False, **kwargs)
|
||||
41
mayan/apps/common/tests/runner.py
Normal file
41
mayan/apps/common/tests/runner.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
from django import apps
|
||||
from django.conf import settings
|
||||
from django.test.runner import DiscoverRunner
|
||||
|
||||
|
||||
class MayanTestRunner(DiscoverRunner):
|
||||
@classmethod
|
||||
def add_arguments(cls, parser):
|
||||
DiscoverRunner.add_arguments(parser)
|
||||
|
||||
def build_suite(self, *args, **kwargs):
|
||||
self.top_level = os.path.join(settings.BASE_DIR, 'apps')
|
||||
|
||||
test_suit = super(MayanTestRunner, self).build_suite(*args, **kwargs)
|
||||
|
||||
new_suite = self.test_suite()
|
||||
|
||||
# Apps that report they have tests
|
||||
|
||||
test_apps = [
|
||||
app.name for app in apps.apps.get_app_configs() if getattr(app, 'test', False)
|
||||
]
|
||||
|
||||
# Filter the test cases reported by the test runner by the apps that
|
||||
# reported tests
|
||||
|
||||
for test_case in test_suit:
|
||||
app_label = repr(test_case.__class__).split("'")[1].split('.')[0]
|
||||
if app_label in test_apps:
|
||||
new_suite.addTest(test_case)
|
||||
|
||||
print '-' * 10
|
||||
print 'Apps to test: {}'.format(', '.join(test_apps))
|
||||
print 'Total test cases: {}'.format(new_suite.countTestCases())
|
||||
print '-' * 10
|
||||
|
||||
return new_suite
|
||||
@@ -234,6 +234,8 @@ STATICFILES_FINDERS = (
|
||||
'compressor.finders.CompressorFinder',
|
||||
)
|
||||
|
||||
TEST_RUNNER = 'common.tests.runner.MayanTestRunner'
|
||||
|
||||
# --------- Django compressor -------------
|
||||
COMPRESS_CSS_FILTERS = (
|
||||
'compressor.filters.css_default.CssAbsoluteFilter',
|
||||
@@ -272,7 +274,6 @@ CELERY_ROUTES = {}
|
||||
CELERY_TASK_SERIALIZER = 'json'
|
||||
CELERY_TIMEZONE = 'UTC'
|
||||
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'
|
||||
TEST_RUNNER = 'djcelery.contrib.test_runner.CeleryTestSuiteRunner'
|
||||
# ------------ CORS ------------
|
||||
CORS_ORIGIN_ALLOW_ALL = True
|
||||
# ------ Django REST Swagger -----
|
||||
|
||||
Reference in New Issue
Block a user