Skip to content

Commit

Permalink
Added an option to run tests without code coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Omer Katz committed Jan 26, 2013
1 parent 0721a55 commit 39668b7
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
build
dist
*.egg-info
.idea
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ Inspired by `django-coverage <https://bitbucket.org/kmike/django-coverage/>`_.
Usage
-----

To run the tests type:

./manage.py test [options] [appname ...]

To run the tests without code coverage (i.e. run django-discover-runner instead) type:

./manage.py test --no-coverage [options] [appname ...]


One of the objectives of ``django-discover-runner`` is to allow the separation
of a Django app's tests from the code it's testing. Since tests no longer reside
in an app, ``django-discoverage`` needs a different way to know which apps to
Expand Down
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions discoverage/management/commands/erasecoveragedata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from coverage import coverage
from django.core.management import BaseCommand

class Command(BaseCommand):
def handle(self, filename, **options):
cov = coverage(data_file=filename)

cov.erase()
17 changes: 17 additions & 0 deletions discoverage/management/commands/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from optparse import make_option
from django.core.management import CommandError

try:
# Depends on a change that will be made on discover runner.
# It can work without it at the time being and therefor the try...except block exists.
# Also, even if there was no expected change, it is useful as a foresight.
from discover_runner.management.commands.test import Command as TestCommand
except ImportError:
from django.core.management.commands.test import Command as TestCommand

class Command(TestCommand):
option_list = TestCommand.option_list + (
make_option('--no-coverage',
action='store_false', dest='perform_coverage', default=True,
help='Specifies that no code coverage will be performed.'),
)
8 changes: 8 additions & 0 deletions discoverage/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@


class DiscoverageRunner(DiscoverRunner):
def __init__(self, perform_coverage=True, **kwargs):
self.perform_coverage = perform_coverage

super(DiscoverageRunner, self).__init__(**kwargs)

def build_suite(self, *args, **kwargs):
if not hasattr(self, '_suite'):
self._suite = super(DiscoverageRunner, self).build_suite(
*args, **kwargs)
return self._suite

def run_tests(self, test_labels, extra_tests=None, **kwargs):
if not self.perform_coverage:
return super(DiscoverageRunner, self).run_tests(test_labels, extra_tests=extra_tests, **kwargs)

cov = coverage.coverage(omit=COVERAGE_OMIT_MODULES)

for pattern in COVERAGE_EXCLUDE_PATTERNS:
Expand Down

0 comments on commit 39668b7

Please sign in to comment.