URL为Django覆盖测试0%,为什么? [英] Django coverage test for URLs 0%, why?

查看:171
本文介绍了URL为Django覆盖测试0%,为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Django Nose。我测试了我的URL,但覆盖率仍然为我提供0%的URL,为什么?


python manage.py测试配置文件


这是我的报导:

 名称封面小姐封面缺少
------------------------------------------ ----------------------
个人资料0 0 100%
个人资料0 0 100%
个人资料。 0001_initial 6 0 100%
profiles.models 0 0 100%
profiles.urls 4 4 0%1-9
---------------- ------------------------------------------------
总计10 4 60%
--------------------------------------- -------------------------

这是我的一个URL测试...



url_tests.py



从$ d $ $ $ $ $ $ $ $















$ b class URLTest(TestCase):

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


解决方案

通常这与在此过程中,coverage.py的启动时间太晚。确保其启动的最简单的方法是在覆盖范围内运行测试运行器:

  $ coverage run nosetests.py .. 

urls.py的一个相关细节:它只包含导入时执行的代码。因此,当Django启动并导入urls.py时,整个文件将被执行。这与大多数文件不同,它们定义稍后执行其身体的类或功能。


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

解决方案

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.

这篇关于URL为Django覆盖测试0%,为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆