Django coverage test for URLs 0%, why?












3















Using Django Nose. I have tests for my URL's but coverage is still giving 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 test...



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









share|improve this question

























  • Without seeing more of your codebase, I'm not sure I can help; I can confirm that moving one of my projects (on Django 1.6) to use django-nose, running python manage.py test --with-coverage and having a test that exercises URLs results in correct coverage reports for my urls.py; so it seems likely this is something to do with your code/usage in particular.

    – James Aylett
    Sep 25 '14 at 16:07
















3















Using Django Nose. I have tests for my URL's but coverage is still giving 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 test...



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









share|improve this question

























  • Without seeing more of your codebase, I'm not sure I can help; I can confirm that moving one of my projects (on Django 1.6) to use django-nose, running python manage.py test --with-coverage and having a test that exercises URLs results in correct coverage reports for my urls.py; so it seems likely this is something to do with your code/usage in particular.

    – James Aylett
    Sep 25 '14 at 16:07














3












3








3


3






Using Django Nose. I have tests for my URL's but coverage is still giving 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 test...



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









share|improve this question
















Using Django Nose. I have tests for my URL's but coverage is still giving 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 test...



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






python django django-testing coverage.py python-coverage






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 29 '16 at 19:07









Oz123

13.4k1878128




13.4k1878128










asked Sep 17 '14 at 20:06









PrometheusPrometheus

8,83027101205




8,83027101205













  • Without seeing more of your codebase, I'm not sure I can help; I can confirm that moving one of my projects (on Django 1.6) to use django-nose, running python manage.py test --with-coverage and having a test that exercises URLs results in correct coverage reports for my urls.py; so it seems likely this is something to do with your code/usage in particular.

    – James Aylett
    Sep 25 '14 at 16:07



















  • Without seeing more of your codebase, I'm not sure I can help; I can confirm that moving one of my projects (on Django 1.6) to use django-nose, running python manage.py test --with-coverage and having a test that exercises URLs results in correct coverage reports for my urls.py; so it seems likely this is something to do with your code/usage in particular.

    – James Aylett
    Sep 25 '14 at 16:07

















Without seeing more of your codebase, I'm not sure I can help; I can confirm that moving one of my projects (on Django 1.6) to use django-nose, running python manage.py test --with-coverage and having a test that exercises URLs results in correct coverage reports for my urls.py; so it seems likely this is something to do with your code/usage in particular.

– James Aylett
Sep 25 '14 at 16:07





Without seeing more of your codebase, I'm not sure I can help; I can confirm that moving one of my projects (on Django 1.6) to use django-nose, running python manage.py test --with-coverage and having a test that exercises URLs results in correct coverage reports for my urls.py; so it seems likely this is something to do with your code/usage in particular.

– James Aylett
Sep 25 '14 at 16:07












1 Answer
1






active

oldest

votes


















2














Usually this has to do with coverage.py being started too late in the process. The simplest way to ensure it starts early enough is to run the test runner under coverage:



$ coverage run nosetests.py ....


One relevant detail of urls.py: it contains only code that executes when it is imported. So the entire file is executed when Django starts up and imports urls.py. This is different than most files, which define classes or functions whose bodies are executed later.






share|improve this answer


























  • I am using Django Nose. However, why would the other tests be ok and not this one? Regardless of the order it should report something unless I am doing the testing of URLs wrong.

    – Prometheus
    Sep 21 '14 at 17:13











  • Coverage can only measure code that is executed after coverage is started. If Django Nose imports (and therefore executes) urls.py before it starts coverage.py, then you will see 0% reported for urls.py

    – Ned Batchelder
    Sep 26 '14 at 15:30











  • Have you tried running your tests under coverage as I've shown in the answer?

    – Ned Batchelder
    Sep 26 '14 at 15:32











  • @Sputnik your test shows that your urls.py was imported and processed, but doesn't directly exercise any of the code in urls.py... as Ned has said, it's likely that Django has already processed your urls.py before the test runner starts measuring coverage

    – Anentropic
    Sep 26 '14 at 17:11











  • @NedBatchelder I have coverage installed by the command coverage is not available

    – Prometheus
    Sep 29 '14 at 10:25











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25899439%2fdjango-coverage-test-for-urls-0-why%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














Usually this has to do with coverage.py being started too late in the process. The simplest way to ensure it starts early enough is to run the test runner under coverage:



$ coverage run nosetests.py ....


One relevant detail of urls.py: it contains only code that executes when it is imported. So the entire file is executed when Django starts up and imports urls.py. This is different than most files, which define classes or functions whose bodies are executed later.






share|improve this answer


























  • I am using Django Nose. However, why would the other tests be ok and not this one? Regardless of the order it should report something unless I am doing the testing of URLs wrong.

    – Prometheus
    Sep 21 '14 at 17:13











  • Coverage can only measure code that is executed after coverage is started. If Django Nose imports (and therefore executes) urls.py before it starts coverage.py, then you will see 0% reported for urls.py

    – Ned Batchelder
    Sep 26 '14 at 15:30











  • Have you tried running your tests under coverage as I've shown in the answer?

    – Ned Batchelder
    Sep 26 '14 at 15:32











  • @Sputnik your test shows that your urls.py was imported and processed, but doesn't directly exercise any of the code in urls.py... as Ned has said, it's likely that Django has already processed your urls.py before the test runner starts measuring coverage

    – Anentropic
    Sep 26 '14 at 17:11











  • @NedBatchelder I have coverage installed by the command coverage is not available

    – Prometheus
    Sep 29 '14 at 10:25
















2














Usually this has to do with coverage.py being started too late in the process. The simplest way to ensure it starts early enough is to run the test runner under coverage:



$ coverage run nosetests.py ....


One relevant detail of urls.py: it contains only code that executes when it is imported. So the entire file is executed when Django starts up and imports urls.py. This is different than most files, which define classes or functions whose bodies are executed later.






share|improve this answer


























  • I am using Django Nose. However, why would the other tests be ok and not this one? Regardless of the order it should report something unless I am doing the testing of URLs wrong.

    – Prometheus
    Sep 21 '14 at 17:13











  • Coverage can only measure code that is executed after coverage is started. If Django Nose imports (and therefore executes) urls.py before it starts coverage.py, then you will see 0% reported for urls.py

    – Ned Batchelder
    Sep 26 '14 at 15:30











  • Have you tried running your tests under coverage as I've shown in the answer?

    – Ned Batchelder
    Sep 26 '14 at 15:32











  • @Sputnik your test shows that your urls.py was imported and processed, but doesn't directly exercise any of the code in urls.py... as Ned has said, it's likely that Django has already processed your urls.py before the test runner starts measuring coverage

    – Anentropic
    Sep 26 '14 at 17:11











  • @NedBatchelder I have coverage installed by the command coverage is not available

    – Prometheus
    Sep 29 '14 at 10:25














2












2








2







Usually this has to do with coverage.py being started too late in the process. The simplest way to ensure it starts early enough is to run the test runner under coverage:



$ coverage run nosetests.py ....


One relevant detail of urls.py: it contains only code that executes when it is imported. So the entire file is executed when Django starts up and imports urls.py. This is different than most files, which define classes or functions whose bodies are executed later.






share|improve this answer















Usually this has to do with coverage.py being started too late in the process. The simplest way to ensure it starts early enough is to run the test runner under coverage:



$ coverage run nosetests.py ....


One relevant detail of urls.py: it contains only code that executes when it is imported. So the entire file is executed when Django starts up and imports urls.py. This is different than most files, which define classes or functions whose bodies are executed later.







share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 26 '14 at 15:31

























answered Sep 18 '14 at 14:28









Ned BatchelderNed Batchelder

257k52445567




257k52445567













  • I am using Django Nose. However, why would the other tests be ok and not this one? Regardless of the order it should report something unless I am doing the testing of URLs wrong.

    – Prometheus
    Sep 21 '14 at 17:13











  • Coverage can only measure code that is executed after coverage is started. If Django Nose imports (and therefore executes) urls.py before it starts coverage.py, then you will see 0% reported for urls.py

    – Ned Batchelder
    Sep 26 '14 at 15:30











  • Have you tried running your tests under coverage as I've shown in the answer?

    – Ned Batchelder
    Sep 26 '14 at 15:32











  • @Sputnik your test shows that your urls.py was imported and processed, but doesn't directly exercise any of the code in urls.py... as Ned has said, it's likely that Django has already processed your urls.py before the test runner starts measuring coverage

    – Anentropic
    Sep 26 '14 at 17:11











  • @NedBatchelder I have coverage installed by the command coverage is not available

    – Prometheus
    Sep 29 '14 at 10:25



















  • I am using Django Nose. However, why would the other tests be ok and not this one? Regardless of the order it should report something unless I am doing the testing of URLs wrong.

    – Prometheus
    Sep 21 '14 at 17:13











  • Coverage can only measure code that is executed after coverage is started. If Django Nose imports (and therefore executes) urls.py before it starts coverage.py, then you will see 0% reported for urls.py

    – Ned Batchelder
    Sep 26 '14 at 15:30











  • Have you tried running your tests under coverage as I've shown in the answer?

    – Ned Batchelder
    Sep 26 '14 at 15:32











  • @Sputnik your test shows that your urls.py was imported and processed, but doesn't directly exercise any of the code in urls.py... as Ned has said, it's likely that Django has already processed your urls.py before the test runner starts measuring coverage

    – Anentropic
    Sep 26 '14 at 17:11











  • @NedBatchelder I have coverage installed by the command coverage is not available

    – Prometheus
    Sep 29 '14 at 10:25

















I am using Django Nose. However, why would the other tests be ok and not this one? Regardless of the order it should report something unless I am doing the testing of URLs wrong.

– Prometheus
Sep 21 '14 at 17:13





I am using Django Nose. However, why would the other tests be ok and not this one? Regardless of the order it should report something unless I am doing the testing of URLs wrong.

– Prometheus
Sep 21 '14 at 17:13













Coverage can only measure code that is executed after coverage is started. If Django Nose imports (and therefore executes) urls.py before it starts coverage.py, then you will see 0% reported for urls.py

– Ned Batchelder
Sep 26 '14 at 15:30





Coverage can only measure code that is executed after coverage is started. If Django Nose imports (and therefore executes) urls.py before it starts coverage.py, then you will see 0% reported for urls.py

– Ned Batchelder
Sep 26 '14 at 15:30













Have you tried running your tests under coverage as I've shown in the answer?

– Ned Batchelder
Sep 26 '14 at 15:32





Have you tried running your tests under coverage as I've shown in the answer?

– Ned Batchelder
Sep 26 '14 at 15:32













@Sputnik your test shows that your urls.py was imported and processed, but doesn't directly exercise any of the code in urls.py... as Ned has said, it's likely that Django has already processed your urls.py before the test runner starts measuring coverage

– Anentropic
Sep 26 '14 at 17:11





@Sputnik your test shows that your urls.py was imported and processed, but doesn't directly exercise any of the code in urls.py... as Ned has said, it's likely that Django has already processed your urls.py before the test runner starts measuring coverage

– Anentropic
Sep 26 '14 at 17:11













@NedBatchelder I have coverage installed by the command coverage is not available

– Prometheus
Sep 29 '14 at 10:25





@NedBatchelder I have coverage installed by the command coverage is not available

– Prometheus
Sep 29 '14 at 10:25


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f25899439%2fdjango-coverage-test-for-urls-0-why%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Callistus III

Ostreoida

Plistias Cous