Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pyc
*.egg-info
9 changes: 5 additions & 4 deletions django_coverage/coverage_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

"""
import os
import sys

import django

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)