Adds coverage to Django's DiscoverRunner.
Inspired by django-coverage.
django-discoverage works with Django 1.4 and above. If you are using Django 1.4 or 1.5, django-discover-runner is required and will be automatically installed. That package backports the implementation of DiscoverRunner included in Django 1.6.
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 …]
If you want to use the --no-coverage option, make sure you add discoverage to your INSTALLED_APPS.
One of the objectives of Django’s DiscoverRunner (previously 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 include in the coverage report. The runner does this in two ways which are discussed below.
First, it tries to infer which apps you are testing from the name of the package in which the test’s module lives. For example, if you have an app blog and you test the view of the app in the module tests.blog.test_views, the app will be included in the coverage report. The same happens if the app is a subpackage and appears in INSTALLED_APPS as myproject.blog.
This behavior is controlled by the PKG_NAME_APP_DISCOVERY setting.
Although not on by default, tested apps can also be guessed from the name of the test’s module. For example, if MODULE_NAME_APP_DISCOVERY is True and there is a module named tests.test_blog, the blog app will be included in the report. You can override the regular expression used to extract the app name using the MODULE_NAME_DISCOVERY_PATTERN setting.
The second way in which django-discoverage finds apps is by looking for an iterable of app names (named by default TESTS_APPS) in three places:
Let’s say you had the following test module, tests.blog.test_views:
TESTS_APPS = ('blog',) class MyTestCase(TestCase): TESTS_APPS = ('mycoolapp', 'myproject.anothercoolapp') ...
All modules in the apps blog, mycoolapp, and myproject.anothercoolapp will be included in the report along with any apps listed in test.blog.TESTS_APPS.
Modules specified in OMIT_MODULES will not, however, appear in the report.
A list of regular expressions that impact coverage reporting. If a line of tested code matches one of the patterns in the list, it will not count as a missed line. See the coverage API documentation for more details.