From 0078600e62bcb8eb37958c9ff5259f1e2b3528bf Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Fri, 17 Feb 2017 18:12:48 -0400 Subject: [PATCH] Add custom tests runner that replaces the custom "runtests" management command. --- .gitlab-ci.yml | 6 +-- .travis.yml | 6 +-- Makefile | 3 -- docs/releases/2.2.rst | 3 ++ .../common/management/commands/runtests.py | 34 --------------- mayan/apps/common/tests/runner.py | 41 +++++++++++++++++++ mayan/settings/base.py | 3 +- tox.ini | 2 +- 8 files changed, 53 insertions(+), 45 deletions(-) delete mode 100644 mayan/apps/common/management/commands/runtests.py create mode 100644 mayan/apps/common/tests/runner.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c9c0de6789..b0d172677e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 diff --git a/.travis.yml b/.travis.yml index fbe358ff14..9591074dfa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: diff --git a/Makefile b/Makefile index 764286dc11..55063ab5f1 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/docs/releases/2.2.rst b/docs/releases/2.2.rst index c26d6b3b25..7a2a48134a 100644 --- a/docs/releases/2.2.rst +++ b/docs/releases/2.2.rst @@ -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. diff --git a/mayan/apps/common/management/commands/runtests.py b/mayan/apps/common/management/commands/runtests.py deleted file mode 100644 index 44832cdff8..0000000000 --- a/mayan/apps/common/management/commands/runtests.py +++ /dev/null @@ -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) diff --git a/mayan/apps/common/tests/runner.py b/mayan/apps/common/tests/runner.py new file mode 100644 index 0000000000..db617c46d6 --- /dev/null +++ b/mayan/apps/common/tests/runner.py @@ -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 diff --git a/mayan/settings/base.py b/mayan/settings/base.py index d51aa6db70..a069ccb18e 100644 --- a/mayan/settings/base.py +++ b/mayan/settings/base.py @@ -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 ----- diff --git a/tox.ini b/tox.ini index a64387cd66..5f801bcb01 100644 --- a/tox.ini +++ b/tox.ini @@ -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