我正在对分配给我的项目进行测试。一切都是通过调用 tox 来触发的。默认测试使用nose运行,它添加了一个覆盖率报告,这是tox调用的命令:
django-admin test -s
和设置文件有这个鼻子的配置:
NOSE_ARGS = [
'--with-coverage',
'--cover-erase',
'--cover-package=app_name',
'--cover-inclusive'
]
这是使用 tox 流鼻涕时显示的报告:
Name Stmts Miss Cover
---------------------------------------------------------------------------
app_name/__init__.py 0 0 100%
app_name/apps.py 3 0 100%
app_name/apps_settings.py 12 2 83%
app_name/base.py 118 27 77%
app_name/choices.py 18 0 100%
app_name/constants.py 6 0 100%
app_name/exceptions.py 10 0 100%
app_name/helpers/__init__.py 0 0 100%
app_name/helpers/util.py 20 10 50%
app_name/management/__init__.py 0 0 100%
app_name/migrations/0001_initial.py 9 0 100%
app_name/migrations/__init__.py 0 0 100%
app_name/mixins.py 6 0 100%
app_name/models.py 64 4 94%
app_name/permissions.py 7 3 57%
app_name/serializers/__init__.py 0 0 100%
app_name/serializers/address_serializer.py 7 0 100%
app_name/serializers/base_response_serializer.py 7 0 100%
app_name/serializers/body_request_user_serializer.py 14 0 100%
app_name/serializers/contact_serializer.py 4 0 100%
app_name/serializers/file_serializer.py 11 2 82%
app_name/serializers/iban_serializer.py 3 0 100%
app_name/serializers/identification_serializer.py 11 2 82%
app_name/serializers/payment_account_serializer.py 3 0 100%
app_name/serializers/transfer_serializer.py 20 10 50%
app_name/services/__init__.py 0 0 100%
app_name/services/authentication_service.py 7 0 100%
app_name/services/document_service.py 23 9 61%
app_name/services/user_service.py 37 21 43%
app_name/services/webhook_service.py 26 7 73%
app_name/storage_backends.py 10 0 100%
app_name/views/__init__.py 0 0 100%
app_name/views/webhook_view.py 25 8 68%
---------------------------------------------------------------------------
TOTAL 481 105 78%
----------------------------------------------------------------------
Ran 5 tests in 4.615s
但是,如果在它之后我运行coverage report
它会显示:
Name Stmts Miss Cover
-----------------------------------------------------------------------------
app_name/__init__.py 0 0 100%
app_name/apps.py 3 0 100%
app_name/apps_settings.py 12 2 83%
app_name/base.py 118 27 77%
app_name/choices.py 18 0 100%
app_name/constants.py 6 0 100%
app_name/decorators.py 10 7 30%
app_name/exceptions.py 10 0 100%
app_name/helpers/__init__.py 0 0 100%
app_name/helpers/util.py 20 10 50%
app_name/management/__init__.py 0 0 100%
app_name/management/commands/__init__.py 0 0 100%
app_name/management/commands/generate_uuid.py 9 4 56%
app_name/migrations/0001_initial.py 9 0 100%
app_name/migrations/__init__.py 0 0 100%
app_name/mixins.py 6 0 100%
app_name/models.py 64 4 94%
app_name/permissions.py 7 3 57%
app_name/serializers/__init__.py 0 0 100%
app_name/serializers/address_serializer.py 7 0 100%
app_name/serializers/base_response_serializer.py 7 0 100%
app_name/serializers/body_request_token_serializer.py 4 0 100%
app_name/serializers/body_request_user_serializer.py 14 0 100%
app_name/serializers/contact_serializer.py 4 0 100%
app_name/serializers/document_serializer.py 7 0 100%
app_name/serializers/file_serializer.py 11 2 82%
app_name/serializers/files_serializer.py 4 0 100%
app_name/serializers/iban_serializer.py 3 0 100%
app_name/serializers/identification_serializer.py 11 2 82%
app_name/serializers/payment_account_serializer.py 3 0 100%
app_name/serializers/transfer_serializer.py 20 10 50%
app_name/serializers/user_information_serializer.py 7 0 100%
app_name/services/__init__.py 0 0 100%
app_name/services/account_service.py 62 45 27%
app_name/services/authentication_service.py 7 0 100%
app_name/services/document_service.py 23 9 61%
app_name/services/method_service.py 23 15 35%
app_name/services/user_service.py 37 21 43%
app_name/services/webhook_service.py 26 7 73%
app_name/storage_backends.py 10 0 100%
app_name/tests/__init__.py 0 0 100%
app_name/tests/apps/__init__.py 0 0 100%
app_name/tests/apps/apps_test.py 9 0 100%
app_name/tests/helpers/__init__.py 0 0 100%
app_name/tests/helpers/helpers_test.py 7 0 100%
app_name/tests/services/__init__.py 0 0 100%
app_name/tests/services/authentication_service_test.py 8 0 100%
app_name/tests/services/document_service_test.py 13 0 100%
app_name/tests/services/user_service_test.py 13 0 100%
app_name/urls/__init__.py 0 0 100%
app_name/urls/webhook_url.py 7 2 71%
app_name/views/__init__.py 0 0 100%
app_name/views/webhook_view.py 25 8 68%
-----------------------------------------------------------------------------
TOTAL 664 178 73%
现在,如您所见,鼻子报告忽略了某些文件,但覆盖率显示了某些文件,例如app_name/services/account_service.py
. 由于该文件包含功能代码,因此应在报告中显示。
有趣的是,据我所知,这两个库:nose 和 coverage 都从同一个报告文件生成它们的报告.coverage
我想这是一个默认的鼻子行为。我对鼻子不是很熟悉,所以也许有人可以告诉我为什么会发生这种行为差异。