diff --git a/.travis.yml b/.travis.yml index a5ce748eb8..55481b7d4b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,14 +7,16 @@ python: services: - mysql - + install: - sudo rm /etc/apt/sources.list.d/mongodb*.list - sudo rm /etc/apt/sources.list.d/docker.list - sudo apt-get install hhvm && rm -rf /home/travis/.kiex/ - sudo apt-get purge -y mysql-common mysql-server mysql-client - nvm install v8.10.0 - + + - pip install python-coveralls + - wget https://raw.githubusercontent.com/frappe/bench/master/playbooks/install.py - sudo python install.py --develop --user travis --without-bench-setup @@ -41,4 +43,7 @@ before_script: - sleep 10 script: - - bench run-tests + - bench run-tests --coverage + +after_script: + - coveralls -b apps/frappe -d ../../sites/.coverage diff --git a/frappe/commands/utils.py b/frappe/commands/utils.py index 6e13cc21e3..5c254040a8 100644 --- a/frappe/commands/utils.py +++ b/frappe/commands/utils.py @@ -6,8 +6,9 @@ import json, os, sys, subprocess from distutils.spawn import find_executable import frappe from frappe.commands import pass_context, get_site -from frappe.utils import update_progress_bar +from frappe.utils import update_progress_bar, get_bench_path from frappe.utils.response import json_handler +from coverage import Coverage @click.command('build') @click.option('--app', help='Build assets for app') @@ -374,12 +375,13 @@ def console(context): @click.option('--ui-tests', is_flag=True, default=False, help="Run UI Tests") @click.option('--module', help="Run tests in a module") @click.option('--profile', is_flag=True, default=False) +@click.option('--coverage', is_flag=True, default=False) @click.option('--skip-test-records', is_flag=True, default=False, help="Don't create test records") @click.option('--skip-before-tests', is_flag=True, default=False, help="Don't run before tests hook") @click.option('--junit-xml-output', help="Destination file path for junit xml report") @pass_context def run_tests(context, app=None, module=None, doctype=None, test=(), - driver=None, profile=False, junit_xml_output=False, ui_tests = False, + driver=None, profile=False, coverage=False, junit_xml_output=False, ui_tests = False, doctype_list_path=None, skip_test_records=False, skip_before_tests=False): "Run tests" import frappe.test_runner @@ -391,9 +393,20 @@ def run_tests(context, app=None, module=None, doctype=None, test=(), frappe.flags.skip_before_tests = skip_before_tests frappe.flags.skip_test_records = skip_test_records + if coverage: + # Generate coverage report only for app that is being tested + source_path = os.path.join(get_bench_path(), 'apps', app or 'frappe', '*') + cov = Coverage(include=source_path, omit=['*.html', '*.js', '*.css']) + cov.start() + ret = frappe.test_runner.main(app, module, doctype, context.verbose, tests=tests, force=context.force, profile=profile, junit_xml_output=junit_xml_output, ui_tests = ui_tests, doctype_list_path = doctype_list_path) + + if coverage: + cov.stop() + cov.save() + if len(ret.failures) == 0 and len(ret.errors) == 0: ret = 0 diff --git a/requirements.txt b/requirements.txt index 973bc69ecf..bd676a94c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -54,3 +54,4 @@ google-auth-httplib2 google-auth-oauthlib faker stripe +coverage