diff --git a/.gitignore b/.gitignore index 0d20b64..7fdea58 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.pyc +*.egg-info diff --git a/README.rst b/README.rst index 29a3e3f..78d6aca 100644 --- a/README.rst +++ b/README.rst @@ -41,6 +41,53 @@ to. You can simply use the test runner if you like. See ``settings.py`` for more detail. 3. Run ``manage.py test`` like you normally do. +Settings +-------- + +All settings are prefixed with ``COVERAGE_``. + + +**TEST_RUNNER** + +Specify the coverage test runner. Default is ``django_coverage.coverage_runner.CoverageRunner`` + +**USE_CACHE** + +Specify whether coverage data file is created or not. Default is ``False``. + +**CODE_EXCLUDES** + +List of regular expressions to exclude in coverage report. + +**PATH_EXCLUDES** + +List of regular expressions of paths to exclude from coverage analysis. + +**ADDITIONNAL_MODULES** + +Specify a list of additional module paths to include in the coverage analysis. + +**MODULE_EXCLUDES** + +Specify a list of regular expressions of module paths to exclude from the coverage analysis. + +**REPORT_HTML_OUTPUT_DIR** + +Directory where coverage report create it's report. + +**CUSTOM_REPORTS** + +``True``, for html reports by 55minutes, ``False`` for coverage.py. + +**USE_STDOUT** + +``True``, always output coverage reports to STDOUT. ``False`` don't. + +**BADGE_TYPE** + +Badge type to create. Default is ``drone.io``. + +For more information about settings, read ``settings.py`` file. Extras ====== @@ -53,7 +100,7 @@ This will be stored in the same directory as the coverage report data: ``$PROJECT/.coverage/coverage_status.png``. Currently, the only badge type that is included is drone.io_. When other -types are included, you will be able to select which is used by +types are included, you will be able to select which is used by ``settings.COVERAGE_BADGE_TYPE``. To prevent the badge generation, you could set this to ``None``. diff --git a/django_coverage/coverage_runner.py b/django_coverage/coverage_runner.py index 8fc95b4..d87d123 100644 --- a/django_coverage/coverage_runner.py +++ b/django_coverage/coverage_runner.py @@ -15,7 +15,6 @@ """ import os -import sys import django @@ -77,9 +76,11 @@ def run_tests(self, test_labels, extra_tests=None, **kwargs): coverage.stop() coverage_modules = [] - if test_labels: + + if test_labels and all( + [len(label.split('.')) >= 2 for label in test_labels]): for label in test_labels: - label = label.split('.')[0] + label = label.split('.')[1] app = get_app(label) coverage_modules.append(self._get_app_package(app)) else: @@ -118,6 +119,6 @@ def run_tests(self, test_labels, extra_tests=None, **kwargs): else: coverage._the_coverage.html_report(list(modules.values()), outdir) print("") - print("HTML reports were output to '%s'" %outdir) + print("HTML reports were output to '%s'" % outdir) return results diff --git a/django_coverage/management/commands/test_coverage.py b/django_coverage/management/commands/test.py similarity index 63% rename from django_coverage/management/commands/test_coverage.py rename to django_coverage/management/commands/test.py index 90dfb83..5404ba9 100755 --- a/django_coverage/management/commands/test_coverage.py +++ b/django_coverage/management/commands/test.py @@ -13,26 +13,31 @@ See the License for the specific language governing permissions and limitations under the License. """ +from optparse import make_option from django.conf import settings -from django.core.management import call_command from django.core.management.commands import test from django_coverage import settings as coverage_settings -class Command(test.Command): - help = ("Runs the test suite for the specified applications, or the " - "entire site if no apps are specified. Then generates coverage " - "report both onscreen and as HTML.") - def handle(self, *test_labels, **options): +class Command(test.Command): + def __init__(self, *args, **kwargs): + super(Command, self).__init__(*args, **kwargs) + self.option_list += ( + make_option( + '--with-coverage', + action="store_true", dest="with_coverage", default=False, + help="Use Coverage TestRunner to generate coverage."), ) + + def handle(self, *args, **kwargs): """ Replaces the original test runner with the coverage test runner, but keeps track of what the original runner was so that the coverage runner can inherit from it. Then, call the test command. This plays well with apps that override the test command, such as South. """ - coverage_settings.ORIG_TEST_RUNNER = settings.TEST_RUNNER - settings.TEST_RUNNER = coverage_settings.COVERAGE_TEST_RUNNER - call_command('test', *test_labels, **options) - + if kwargs.get('with_coverage'): + coverage_settings.ORIG_TEST_RUNNER = settings.TEST_RUNNER + settings.TEST_RUNNER = coverage_settings.COVERAGE_TEST_RUNNER + super(Command, self).handle(*args, **kwargs)