Skip to content

Commit d1ca6cf

Browse files
committed
Merge pull request #2 from thedrow/develop
Added an option to run tests without code coverage.
2 parents 0721a55 + 39668b7 commit d1ca6cf

File tree

7 files changed

+43
-0
lines changed

7 files changed

+43
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
build
77
dist
88
*.egg-info
9+
.idea

README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ Inspired by `django-coverage <https://bitbucket.org/kmike/django-coverage/>`_.
1010
Usage
1111
-----
1212

13+
To run the tests type:
14+
15+
./manage.py test [options] [appname ...]
16+
17+
To run the tests without code coverage (i.e. run django-discover-runner instead) type:
18+
19+
./manage.py test --no-coverage [options] [appname ...]
20+
21+
1322
One of the objectives of ``django-discover-runner`` is to allow the separation
1423
of a Django app's tests from the code it's testing. Since tests no longer reside
1524
in an app, ``django-discoverage`` needs a different way to know which apps to

discoverage/management/__init__.py

Whitespace-only changes.

discoverage/management/commands/__init__.py

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from coverage import coverage
2+
from django.core.management import BaseCommand
3+
4+
class Command(BaseCommand):
5+
def handle(self, filename, **options):
6+
cov = coverage(data_file=filename)
7+
8+
cov.erase()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from optparse import make_option
2+
from django.core.management import CommandError
3+
4+
try:
5+
# Depends on a change that will be made on discover runner.
6+
# It can work without it at the time being and therefor the try...except block exists.
7+
# Also, even if there was no expected change, it is useful as a foresight.
8+
from discover_runner.management.commands.test import Command as TestCommand
9+
except ImportError:
10+
from django.core.management.commands.test import Command as TestCommand
11+
12+
class Command(TestCommand):
13+
option_list = TestCommand.option_list + (
14+
make_option('--no-coverage',
15+
action='store_false', dest='perform_coverage', default=True,
16+
help='Specifies that no code coverage will be performed.'),
17+
)

discoverage/runner.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@
66

77

88
class DiscoverageRunner(DiscoverRunner):
9+
def __init__(self, perform_coverage=True, **kwargs):
10+
self.perform_coverage = perform_coverage
11+
12+
super(DiscoverageRunner, self).__init__(**kwargs)
13+
914
def build_suite(self, *args, **kwargs):
1015
if not hasattr(self, '_suite'):
1116
self._suite = super(DiscoverageRunner, self).build_suite(
1217
*args, **kwargs)
1318
return self._suite
1419

1520
def run_tests(self, test_labels, extra_tests=None, **kwargs):
21+
if not self.perform_coverage:
22+
return super(DiscoverageRunner, self).run_tests(test_labels, extra_tests=extra_tests, **kwargs)
23+
1624
cov = coverage.coverage(omit=COVERAGE_OMIT_MODULES)
1725

1826
for pattern in COVERAGE_EXCLUDE_PATTERNS:

0 commit comments

Comments
 (0)