我已经对我用 django 的 cookie 切割器设置的项目进行了报道。在报告中,coverage 包括 cookie 切割器为我设置的用户应用程序中的 py 文件,包括我的 html 模板,但不包括我的任何 py 文件。
我希望覆盖范围包括我的 6 个应用程序下的几个 py 文件。我必须做什么?
我附上我的报道报告的屏幕截图。
百分比还不错,但我的大量 .py 文件不在报告中。
我正在使用 cookie 切割器为我生成的(稍微修改过的)测试设置文件来实现:
from .base import * # noqa
# DEBUG
# ------------------------------------------------------------------------------
# Turn debug off so tests run faster
DEBUG = False
# coverage throws error unless the following is set to True
TEMPLATES[0]['OPTIONS']['debug'] = True
# SECRET CONFIGURATION
# ------------------------------------------------------------------------------
# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key
# Note: This key only used for development and testing.
SECRET_KEY = env('DJANGO_SECRET_KEY', default='CHANGEME!!!')
# Mail settings
# ------------------------------------------------------------------------------
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
# In-memory email backend stores messages in django.core.mail.outbox
# for unit testing purposes
EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
# CACHING
# ------------------------------------------------------------------------------
# Speed advantages of in-memory caching without having to run Memcached
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': ''
}
}
# TESTING
# ------------------------------------------------------------------------------
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
# PASSWORD HASHING
# ------------------------------------------------------------------------------
# Use fast password hasher so tests run faster
PASSWORD_HASHERS = [
'django.contrib.auth.hashers.MD5PasswordHasher',
]
# TEMPLATE LOADERS
# ------------------------------------------------------------------------------
# Keep templates in memory so tests run faster
TEMPLATES[0]['OPTIONS']['loaders'] = [
['django.template.loaders.cached.Loader', [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
], ],
]
要运行覆盖,这是我的 shell 命令:
覆盖运行 manage.py test --settings=config.settings.test
当我运行 python manage.py test 时,输出显示 65 个测试。
协助将不胜感激。
谢谢!