Django coverage test for 0% urls, why?

Using Django Nose. I have tests for my url, but coverage still gives me 0% for urls, why?

python manage.py test profiles

This is my coverage:

Name                               Stmts   Miss  Cover   Missing
----------------------------------------------------------------
profiles                               0      0   100%
profiles.migrations                    0      0   100%
profiles.migrations.0001_initial       6      0   100%
profiles.models                        0      0   100%
profiles.urls                          4      4     0%   1-9
----------------------------------------------------------------
TOTAL                                 10      4    60%
----------------------------------------------------------------

      

This is one of my url tests ...

url_tests.py

import nose.tools as noz
from django.test import TestCase
from django.core.urlresolvers import resolve, reverse

class URLsTest(TestCase):

    def test_user_list(self):
        url = reverse('api_user_list', args=[])
        noz.assert_equal(url, '/api/user/')

      

+3


source to share


1 answer


This is usually due to the service.py being started too late. The easiest way to ensure it runs early enough is to run the reach test runner:

$ coverage run nosetests.py ....

      



One important detail of urls.py: it only contains the code that is executed when it is imported. This way the entire file gets executed when Django starts up and imports urls.py. This differs from most files that define classes or functions whose bodies are executed later.

+2


source







All Articles