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 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 ...

import 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/')



source to share

1 answer

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

$ coverage run ....


One important detail of 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 This differs from most files that define classes or functions whose bodies are executed later.



All Articles