For a given python file that has the following lines at the top:
对于给定的python文件,其顶部有以下行:
import traceback
import datetime
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.conf import settings
How do I write unit tests that will result in nose not showing 'missing' for those lines?
如何编写单元测试,导致鼻子没有显示“缺失”的那些线?
1 个解决方案
#1
0
I think if it shows those lines as missing in code coverage, that means that this module was never used or imported. Those lines will show as covered in the report as long as you are successful importing those modules, and no extra tests are needed to validate the ability to import those well tested django modules. As long as you have a single test that tests something in that module, you should be fine. For example:
我认为如果它在代码覆盖率中显示缺少这些行,则意味着该模块从未被使用或导入过。只要您成功导入这些模块,这些行将在报告中显示,并且不需要额外的测试来验证导入那些经过良好测试的django模块的能力。只要你有一个测试该模块中的东西的测试,你应该没问题。例如:
import traceback
import datetime
# from django.contrib.contenttypes import generic
# from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.conf import settings
def foo(a):
return a + 5
def test_foo():
assert foo(5) == 10
will result in 100% coverage when running under nose with --with-coverage
option for this particular file. I commented out django.contrib
packages because I'm not using django-nose
and do not have proper settings for this example, but it should not matter.
使用--with-coverage选项为此特定文件运行时,将导致100%覆盖率。我注释掉了django.contrib软件包,因为我没有使用django-nose而且没有适合这个例子的设置,但它应该没关系。
#1
0
I think if it shows those lines as missing in code coverage, that means that this module was never used or imported. Those lines will show as covered in the report as long as you are successful importing those modules, and no extra tests are needed to validate the ability to import those well tested django modules. As long as you have a single test that tests something in that module, you should be fine. For example:
我认为如果它在代码覆盖率中显示缺少这些行,则意味着该模块从未被使用或导入过。只要您成功导入这些模块,这些行将在报告中显示,并且不需要额外的测试来验证导入那些经过良好测试的django模块的能力。只要你有一个测试该模块中的东西的测试,你应该没问题。例如:
import traceback
import datetime
# from django.contrib.contenttypes import generic
# from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.conf import settings
def foo(a):
return a + 5
def test_foo():
assert foo(5) == 10
will result in 100% coverage when running under nose with --with-coverage
option for this particular file. I commented out django.contrib
packages because I'm not using django-nose
and do not have proper settings for this example, but it should not matter.
使用--with-coverage选项为此特定文件运行时,将导致100%覆盖率。我注释掉了django.contrib软件包,因为我没有使用django-nose而且没有适合这个例子的设置,但它应该没关系。