Created
July 20, 2011 18:23
-
-
Save audreyfeldroy/1095555 to your computer and use it in GitHub Desktop.
Django coverage walkthrough
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Here is my django-coverage walkthrough. A nice minimal sample project showing django-coverage in action is https://github.com/pydanny/django-party-pack | |
1) Add to requirements.txt: | |
django-coverage==1.2 | |
coverage==3.4 | |
2) In your virtualenv, do a "pip install -r requirements.txt" | |
3) Add to settings.py: | |
TEST_RUNNER = 'testrunner.OurCoverageRunner' | |
COVERAGE_MODULE_EXCLUDES = [ | |
'tests$', 'settings$', 'urls$', 'locale$', | |
'migrations', 'fixtures', 'admin$', | |
] | |
COVERAGE_MODULE_EXCLUDES += PREREQ_APPS | |
COVERAGE_REPORT_HTML_OUTPUT_DIR = "coverage" | |
4) Create testrunner.py: | |
# Make our own testrunner that by default only tests our own apps | |
from django.conf import settings | |
from django.test.simple import DjangoTestSuiteRunner | |
from django_coverage.coverage_runner import CoverageRunner | |
# TODO write something that generates a coverage folder if it doesn't already exist | |
class OurTestRunner(DjangoTestSuiteRunner): | |
def build_suite(self, test_labels, *args, **kwargs): | |
return super(OurTestRunner, self).build_suite(test_labels or settings.PROJECT_APPS, *args, **kwargs) | |
class OurCoverageRunner(OurTestRunner, CoverageRunner): | |
pass | |
5) Inside your Django project directory, "mkdir coverage" | |
6) Add to your .gitignore file: | |
coverage/ | |
7) Run python manage.py test | |
8) Open file:///path-to-your-project/coverage/index.html in a web browser. You should see a pretty coverage report. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment