Add custom tests runner that replaces the custom "runtests"

management command.
This commit is contained in:
Roberto Rosario
2017-02-17 18:12:48 -04:00
parent df4aabcc0a
commit 0078600e62
8 changed files with 53 additions and 45 deletions

View File

@@ -21,7 +21,7 @@ test:mysql:
- pip install mysql-python
- apt-get install -qq mysql-client
- mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD" -e "set global character_set_server=utf8mb4;"
- coverage run manage.py runtests --settings=mayan.settings.testing.gitlab-ci.db_mysql --nomigrations
- coverage run manage.py test --settings=mayan.settings.testing.gitlab-ci.db_mysql --nomigrations
- bash <(curl https://raw.githubusercontent.com/codecov/codecov-bash/master/codecov) -t $CODECOV_TOKEN
tags:
- mysql
@@ -30,12 +30,12 @@ test:postgres:
- apt-get install -qq libpq-dev
- pip install -r requirements/testing.txt
- pip install psycopg2
- coverage run manage.py runtests --settings=mayan.settings.testing.gitlab-ci.db_postgres --nomigrations
- coverage run manage.py test --settings=mayan.settings.testing.gitlab-ci.db_postgres --nomigrations
- bash <(curl https://raw.githubusercontent.com/codecov/codecov-bash/master/codecov) -t $CODECOV_TOKEN
tags:
- postgres
test:sqlite:
script:
- pip install -r requirements/testing.txt
- coverage run manage.py runtests --settings=mayan.settings.testing.gitlab-ci --nomigrations
- coverage run manage.py test --settings=mayan.settings.testing.gitlab-ci --nomigrations
- bash <(curl https://raw.githubusercontent.com/codecov/codecov-bash/master/codecov) -t $CODECOV_TOKEN

View File

@@ -17,9 +17,9 @@ before_script:
- mysql -e 'create database mayan_edms;'
- psql -c 'create database mayan_edms;' -U postgres
script:
- if [[ $DB == mysql ]]; then coverage run manage.py runtests --settings=mayan.settings.testing.travis.db_mysql --nomigrations; fi
- if [[ $DB == postgres ]]; then coverage run manage.py runtests --settings=mayan.settings.testing.travis.db_postgres --nomigrations; fi
- if [[ $DB == sqlite ]]; then coverage run manage.py runtests --settings=mayan.settings.testing.base --nomigrations; fi
- if [[ $DB == mysql ]]; then coverage run manage.py test --settings=mayan.settings.testing.travis.db_mysql --nomigrations; fi
- if [[ $DB == postgres ]]; then coverage run manage.py test --settings=mayan.settings.testing.travis.db_postgres --nomigrations; fi
- if [[ $DB == sqlite ]]; then coverage run manage.py test --settings=mayan.settings.testing.base --nomigrations; fi
after_success:
- coveralls
branches:

View File

@@ -51,9 +51,6 @@ clean-pyc:
test:
./manage.py test $(MODULE) --settings=mayan.settings.testing --nomigrations
test-all:
./manage.py runtests --settings=mayan.settings.testing --nomigrations
# Documentation

View File

@@ -92,6 +92,9 @@ Other changes
- Gaussian blur
- Unsharp masking
- Add custom test runner replacing the custom management command runtests.
The 'test-all' Makefile target that called the `runtests` command has been removed too.
Removals
--------
- Removal of the OCR_TESSERACT_PATH configuration setting.

View File

@@ -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)

View 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

View File

@@ -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 -----

View File

@@ -12,7 +12,7 @@ basepython =
py35: python3.5
commands=
coverage run {envdir}/bin/django-admin.py runtests --settings=mayan.settings.testing --nomigrations
coverage run {envdir}/bin/django-admin.py test --settings=mayan.settings.testing --nomigrations
deps =
-rrequirements/testing-no-django.txt